React Tree Grid Sorting

    The Ignite UI for React Data Sorting feature in React Tree Grid is enabled on a per-column level, meaning that the IgrTreeGrid can have a mix of sortable and non-sortable columns. Performing React sort actions enables you to change the display order of the records based on specified criteria.

    React Tree Grid Sorting Overview Example

    This is done via the sortable input. With the IgrTreeGrid sorting, you can also set the sortingIgnoreCase property to perform case sensitive sorting:

    <IgrColumn field="ProductName" header="Product Name" dataType="string" sortable={true}></IgrColumn>
    

    Sorting Indicators

    정렬된 순서가 표시되지 않으면 일정량의 열이 정렬되어 있으면 정말 혼란스러울 수 있습니다.

    The IgrTreeGrid provides a solution for this problem by indicating the index of each sorted column.

    Sorting through the API

    You can sort any column or a combination of columns through the IgrTreeGrid API using the IgrTreeGrid sort method:

    import { SortingDirection } from "igniteui-react-grids";
    
    // Perform a case insensitive ascending sort on the Category column.
    treeGridRef.current.sort([{ fieldName: 'Category', dir: SortingDirection.Asc, ignoreCase: true }]);
    
    // Perform sorting on both the Category and Price columns.
    treeGridRef.current.sort([
        { fieldName: 'Category', dir: SortingDirection.Asc, ignoreCase: true },
        { fieldName: 'Price', dir: SortingDirection.Desc }
    ]);
    

    [!Note] Sorting is performed using our DefaultSortingStrategy algorithm. Any IgrColumn or ISortingExpression can use a custom implementation of the ISortingStrategy as a substitute algorithm. This is useful when custom sorting needs to be defined for complex template columns, or image columns, for example.

    As with the filtering behavior, you can clear the sorting state by using the clearSort method:

    // Removes the sorting state from the Category column
    treeGridRef.current.clearSort('Category');
    
    // Removes the sorting state from every column in the Tree Grid
    treeGridRef.current.clearSort();
    

    [!Note] The sortStrategy of the IgrTreeGrid is of different type compared to the sortStrategy of the IgrColumn, since they work in different scopes and expose different parameters.

    [!Note] The sorting operation DOES NOT change the underlying data source of the IgrTreeGrid.

    Initial Sorting State

    It is possible to set the initial sorting state of the IgrTreeGrid by passing an array of sorting expressions to the sortingExpressions property of the IgrTreeGrid.

    const sortingExpressions: IgrSortingExpression[] = [
        { fieldName: 'Category', dir: SortingDirection.Asc, ignoreCase: true },
        { fieldName: 'Price', dir: SortingDirection.Desc }
    ];
    
    <IgrTreeGrid
        data={productSales}
        sortingExpressions={sortingExpressions}>
    </IgrTreeGrid>
    

    [!Note] If values of type string are used by a column of dataType Date, the IgrTreeGrid won't parse them to Date objects and using IgrTreeGrid Sorting won't work as expected. If you want to use string objects, additional logic should be implemented on an application level, in order to parse the values to Date objects.

    Sorting Indicators Templates

    열 머리글의 정렬 표시기 아이콘은 템플릿을 사용하여 사용자 정의할 수 있습니다. 모든 정렬 상태(오름차순, 내림차순, 없음)에 대한 정렬 표시기 템플릿을 작성하는 데 다음 속성을 사용할 수 있습니다.

    const sortHeaderIconTemplate = (ctx: IgrGridHeaderTemplateContext) => {
        return (
            <>
                <IgrIcon name='unfold_more'></IgrIcon>
            </>
        );
    }
    
    <IgrTreeGrid sortHeaderIconTemplate={sortHeaderIconTemplate}></IgrTreeGrid>
    
    const sortAscendingHeaderIconTemplate = (ctx: IgrGridHeaderTemplateContext) => {
        return (
            <>
                <IgrIcon name='expand_less'></IgrIcon>
            </>
        );
    }
    
    <IgrTreeGrid sortAscendingHeaderIconTemplate={sortAscendingHeaderIconTemplate}></IgrTreeGrid>
    
    const sortDescendingHeaderIconTemplate = (ctx: IgrGridHeaderTemplateContext) => {
        return (
            <>
                <IgrIcon name='expand_more'></IgrIcon>
            </>
        );
    }
    
    <IgrTreeGrid sortDescendingHeaderIconTemplate={sortDescendingHeaderIconTemplate}></IgrTreeGrid>
    

    Styling

    사전 정의된 테마 외에도 사용 가능한 CSS 속성 중 일부를 설정하여 그리드를 추가로 사용자 정의할 수 있습니다. 일부 색상을 변경하려면 먼저 그리드에 대한 클래스를 설정해야 합니다.

    <IgrTreeGrid className="grid">
    </IgrTreeGrid>
    

    그런 다음 관련 CSS 속성을 이 클래스로 설정합니다.

    .grid {
        --ig-grid-sorted-header-icon-color: #ffb06a;
        --ig-grid-sortable-header-icon-hover-color: black;
    }
    

    Demo

    API References

    Additional Resources

    우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.