Blazor 그리드 정렬

    Blazor Grid의 Ignite UI for Blazor 열별 수준에서 활성화됩니다. 즉, IgbGrid 에는 정렬 가능한 열과 정렬 불가능한 열이 혼합되어 있을 수 있습니다. Blazor 정렬 작업을 수행하면 지정된 기준에 따라 레코드의 표시 순서를 변경할 수 있습니다.

    Blazor Grid Sorting Overview Example

    이는 Sortable 입력을 통해 수행됩니다. IgbGrid 정렬을 사용하면 SortingIgnoreCase 속성을 설정하여 대소문자 구분 정렬을 수행할 수도 있습니다.

    <IgbColumn Field="Title" Sortable="true"></IgbColumn>
    

    Sorting Indicators

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

    IgbGrid는 정렬된 각 열의 인덱스를 표시하여 이 문제에 대한 솔루션을 제공합니다.

    Sorting through the API

    IgbGrid​ ​Sort 메서드를 사용하여 IgbGrid API를 통해 모든 열 또는 열 조합을 정렬할 수 있습니다.

    @code {
        this.grid.SortAsync(new IgbSortingExpression[]
            {
                new IgbSortingExpression
                {
                    FieldName = "CompanyName",
                    Dir = SortingDirection.Asc
                },
                new IgbSortingExpression
                {
                    FieldName = "Country",
                    Dir = SortingDirection.Asc
                }
            });
    }
    

    [!Note] Sorting is performed using our DefaultSortingStrategy algorithm. Any IgbColumn 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.

    필터링 동작과 마찬가지로 ClearSort 메서드를 사용하여 정렬 상태를 지울 수 있습니다.

    @code {
        @*Removes the sorting state from the Title column*@
        this.grid.ClearSortAsync("Title");
    
        @*Removes the sorting state from every column in the Grid*@
        this.grid.ClearSortAsync("");
    }
    

    [!Note] The SortStrategy of the IgbGrid is of different type compared to the SortStrategy of the IgbColumn, since they work in different scopes and expose different parameters.

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

    Initial Sorting State

    IgbGridSortingExpressions 속성에 정렬 표현식 배열을 전달하여 IgbGrid의 초기 정렬 상태를 설정할 수 있습니다.

    @code {
        protected override void OnAfterRender(bool first)
        {
            if (first)
            {
                this.grid.SortingExpressions = new IgbSortingExpression[]{
                    new IgbSortingExpression()
                    {
                        FieldName = "Title",
                        Dir = SortingDirection.Asc
                    }};
            }
        }
    }
    

    [!Note] If values of type string are used by a column of DataType Date, the IgbGrid won't parse them to Date objects and using IgbGrid 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

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

    • SortHeaderIconTemplate– 정렬이 적용되지 않을 때 정렬 아이콘의 템플릿을 다시 지정합니다.
    <IgbGrid SortHeaderIconTemplate="SortDefaultTemplate"></IgbGrid>
    
    @code {
        public RenderFragment<IgbGridHeaderTemplateContext> SortDefaultTemplate = (ctx) =>
        {
            return @<IgbIcon Size="SizableComponentSize.Small" IconName="unfold_more" Collection="material"></IgbIcon>;
        };
    }
    
    <IgbGrid SortAscendingHeaderIconTemplate="SortAscendingTemplate"></IgbGrid>
    
    @code {
        public RenderFragment<IgbGridHeaderTemplateContext> SortAscendingTemplate = (ctx) =>
        {
            return @<IgbIcon Size="SizableComponentSize.Small" IconName="expand_less" Collection="material"></IgbIcon>;
        };
    }
    
    <IgbGrid SortDescendingHeaderIconTemplate="SortDescendingTemplate"></IgbGrid>
    
    @code {
        public RenderFragment<IgbGridHeaderTemplateContext> SortDescendingTemplate = (ctx) =>
        {
            return @<IgbIcon Size="SizableComponentSize.Small" IconName="expand_more" Collection="material"></IgbIcon>;
        };
    }
    

    Styling

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

    <IgbGrid class="grid">
    </IgbGrid>
    

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

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

    Demo

    API References

    Additional Resources

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