Blazor 트리 그리드 개요 및 구성

    Blazor 트리 그리드는 데이터 그리드(테이블)의 기능과 트리 뷰를 결합하여 계층적 데이터를 표 형식으로 쉽게 표시할 수 있는 UI 구성 요소입니다. 일반 그리드와 달리 트리 그리드를 사용하면 행을 확장 및 축소할 수 있어 상위 행 아래에 중첩된 자식 행이 표시되므로 파일 탐색기, 조직도, 프로젝트 작업 또는 제품 범주와 같은 구조화된 데이터를 나타내는 데 유용합니다.

    Ignite UI for Blazor Tree Grid는 계층적 또는 플랫 데이터를 쉽게 표시하고 조작하는 데 사용됩니다. 매우 적은 코드로 데이터를 빠르게 바인딩하거나 다양한 이벤트를 사용하여 다양한 동작을 사용자 정의합니다. 이 구성 요소는 데이터 선택, Excel 스타일 필터링, 정렬, 페이지 지정, 템플릿 및 열 이동과 같은 풍부한 기능 세트를 제공합니다. Material Table 기반 UI Tree Grid 덕분에 표 형식 데이터를 표시하는 것이 그 어느 때보다 쉽고 아름다워졌습니다.

    Blazor Tree Grid Example

    이 예에서는 사용자가 계층적 또는 단순 데이터를 조작하는 방법을 볼 수 있습니다. 필터링 및 정렬 옵션, 고정 및 숨기기, 행 선택, Excel 및 CSV로 내보내기가 포함되었습니다.

    Example

    Getting Started with Ignite UI for Blazor Tree Grid

    Dependencies

    Blazor 그리드 라이브러리와 특히 Blazor 트리 그리드를 시작하는 것은 계층적 정보를 명확하고 대화형 방식으로 표시하는 강력하고 데이터가 풍부한 애플리케이션을 구축하기 위한 첫 번째 단계입니다. Blazor 트리 그리드를 사용하면 대규모 데이터 세트에서 고성능을 위해 행 확장, 정렬, 필터링, 편집 및 가상화와 같은 기능을 갖춘 친숙한 표 형식으로 부모-자식 데이터 구조를 표시할 수 있습니다.

    To get started with the Blazor tree grid, first you need to install the IgniteUI.Blazor package.

    IgniteUI.Blazor 패키지 추가에 대한 다음 항목을 참조하십시오.

    또한 트리 그리드에 필요한 스타일을 제공하려면 애플리케이션의 index.html 파일에 다음 CSS 링크를 포함해야 합니다.

    <link href="_content/IgniteUI.Blazor/themes/grid/light/bootstrap.css" rel="stylesheet" />
    

    그런 다음 다음 네임스페이스를 추가하여 컨트롤 구현을 시작할 수 있습니다.

    @using IgniteUI.Blazor.Controls
    

    Component Modules

    // in Program.cs file
    
    builder.Services.AddIgniteUIBlazor(typeof(IgbTreeGridModule));
    

    Usage

    트리 그리드는 그리드와 많은 기능을 공유하지만 데이터를 계층적으로 표시하는 기능도 추가합니다. 이를 달성하기 위해 트리 그리드는 모든 데이터 개체에 대해 하위 컬렉션을 사용하거나 모든 데이터 개체에 대해 기본 및 외래 키를 사용하여 데이터 개체 간의 관계를 정의하는 몇 가지 방법을 제공합니다.

    Tree Cells

    트리 그리드의 계층 구조(하위 컬렉션 또는 기본 및 외래 키)를 구축하는 데 사용되는 옵션에 관계없이 트리 그리드의 행은 두 가지 유형의 셀로 구성됩니다.

    • GridCell - Ordinary cell that contains a value.
    • TreeGridCell - Tree cell that contains a value, an expand/collapse indicator and an indentation div element, which is based on the level of the cell's row. The level of a row component can be accessed through the level property of its inner treeRow.

    [!Note] Each row can have only one tree cell, but it can have multiple (or none) ordinary cells.

    Initial Expansion Depth

    Initially the tree grid will expand all node levels and show them. This behavior can be configured using the ExpansionDepth property. By default its value is Infinity which means all node levels will be expanded. You may control the initial expansion depth by setting this property to a numeric value. For example 0 will show only root level nodes, 1 will show root level nodes and their child nodes and so on.

    Child Collection

    자식 컬렉션 옵션을 사용하는 경우 모든 데이터 개체에는 부모 데이터 개체와 동일한 유형의 항목으로 채워지는 자식 컬렉션이 포함됩니다. 이렇게 하면 트리 그리드의 모든 레코드가 자식에 대한 직접 참조를 갖게 됩니다. 이 경우 원래 데이터 원본을 포함하는 트리 표의 데이터 속성은 계층적으로 정의된 컬렉션이 됩니다.

    이 샘플에서는 다음 컬렉션 구조를 사용해 보겠습니다.

    public class EmployeesNestedDataItem
    {
        public double ID { get; set; }
        public double Age { get; set; }
        public double Salary { get; set; }
        public double Productivity { get; set; }
        public string City { get; set; }
        public string Country { get; set; }
        public string Phone { get; set; }
        public string HireDate { get; set; }
        public string Name { get; set; }
        public string Title { get; set; }
        public List<EmployeesItem> Employees { get; set; }
    }
    public class EmployeesItem
    {
        public double Age { get; set; }
        public double Salary { get; set; }
        public double Productivity { get; set; }
        public string City { get; set; }
        public string Country { get; set; }
        public string Phone { get; set; }
        public string HireDate { get; set; }
        public double ID { get; set; }
        public string Name { get; set; }
        public string Title { get; set; }
    }
    

    Now let's start by importing our Data collection and binding it to our tree grid.

     <IgbTreeGrid
        AutoGenerate="false"
        ChildDataKey="Employees"
        Data="EmployeesNestedData"
        Name="treeGrid"
        @ref="treeGrid">
            <IgbColumn Field="Name" DataType="GridColumnDataType.String"></IgbColumn>
            <IgbColumn Field="HireDate" DataType="GridColumnDataType.Date"></IgbColumn>
            <IgbColumn Field="Age" DataType="GridColumnDataType.Number"> </IgbColumn>
    </IgbTreeGrid>
    

    In order for the tree grid to build the hierarchy, we will have to set its ChildDataKey property to the name of the child collection that is used in each of our data objects. In our case that will be the Employees collection. In addition, we can disable the automatic column generation and define them manually by matching them to the actual properties of our data objects. (The Employees collection will be automatically used for the hierarchy, so there is no need to include it in the columns' definitions.)

    We can now enable the row selection and paging features of the tree grid by using the RowSelection and add the IgbPaginator element. We can also enable the summaries, the filtering, sorting, editing, moving and resizing features for each of our columns.

    <IgbTreeGrid AutoGenerate="false"
                 ChildDataKey="Employees"
                 Data="EmployeesNestedData"
                 RowSelection="GridSelectionMode.Multiple"
                 AllowFiltering=true
                 Moving=true
                Name="treeGrid"
                @ref="treeGrid">
        <IgbColumn Field="Name" DataType="GridColumnDataType.String" Sortable=true Editable=true Resizable=true HasSummary=true></IgbColumn>
        <IgbColumn Field="HireDate" DataType="GridColumnDataType.Date" Sortable=true Editable=true Resizable=true HasSummary=true></IgbColumn>
        <IgbColumn Field="Age" DataType="GridColumnDataType.Number" Sortable=true Editable=true Resizable=true HasSummary=true> </IgbColumn>
        <IgbPaginator></IgbPaginator>
    </IgbTreeGrid>
    

    Finally, we can enable the toolbar of our tree grid, along with the column hiding, column pinning and exporting features by using the IgbGridToolbar, IgbGridToolbarHiding, IgbGridToolbarPinning and IgbGridToolbarExporter respectively.

    <IgbTreeGrid AutoGenerate="false"
                 ChildDataKey="Employees"
                 Data="EmployeesNestedData"
                 RowSelection="GridSelectionMode.Multiple"
                 AllowFiltering=true
                 Moving=true
                Name="treeGrid"
                @ref="treeGrid">
        <IgbColumn Field="Name" DataType="GridColumnDataType.String" Sortable=true Editable=true Resizable=true HasSummary=true></IgbColumn>
        <IgbColumn Field="HireDate" DataType="GridColumnDataType.Date" Sortable=true Editable=true Resizable=true></IgbColumn>
        <IgbColumn Field="Age" DataType="GridColumnDataType.Number" Sortable=true Editable=true Resizable=true > </IgbColumn>
        <IgbPaginator></IgbPaginator>
        <IgbGridToolbar>
            <IgbGridToolbarTitle> Employees </IgbGridToolbarTitle>
            <IgbGridToolbarActions>
                <IgbGridPinningActions></IgbGridPinningActions>
                <IgbGridToolbarHiding></IgbGridToolbarHiding>
                <IgbGridToolbarExporter></IgbGridToolbarExporter>
        </IgbGridToolbarActions>
        </IgbGridToolbar>
    </IgbTreeGrid>
    

    이 문서의 시작 부분에 있는 트리 그리드 예제 섹션에서 위 코드의 결과를 볼 수 있습니다.

    Primary and Foreign keys

    When we are using the primary and foreign keys option, every data object contains a primary key and a foreign key. The primary key is the unique identifier of the current data object and the foreign key is the unique identifier of its parent. In this case the data property of our tree grid that contains the original data source will be a flat collection.

    public class EmployeesFlatDataItem
    {
        public double Age { get; set; }
        public string HireDate { get; set; }
        public double ID { get; set; }
        public string Name { get; set; }
        public string Phone { get; set; }
        public bool OnPTO { get; set; }
        public double ParentID { get; set; }
        public string Title { get; set; }
    }
    

    In the sample data above, all records have an ID, a ParentID and some additional properties like Name, JobTitle and Age. As mentioned previously, the ID of the records must be unique as it will be our PrimaryKey. The ParentID contains the ID of the parent node and could be set as a ForeignKey. If a row has a ParentID that does not match any row in the tree grid, then that means this row is a root row.

    The parent-child relation is configured using the tree grid's PrimaryKey and ForeignKey properties.

    다음은 위의 플랫 컬렉션에 정의된 데이터를 표시하도록 트리 그리드를 구성하는 방법을 보여주는 구성 요소의 템플릿입니다.

    <IgbTreeGrid AutoGenerate="false"
                 PrimaryKey="ID"
                 ForeignKey="ParentID"
                 Data="EmployeesFlatDataItem"
                 Name="treeGrid">
        <IgbColumn Field="Name" DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumn Field="JobTitle" DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumn Field="Age" DataType="GridColumnDataType.Number"></IgbColumn>
    </IgbTreeGrid>
    

    또한 rowSelection 속성을 사용하여 트리 그리드의 행 선택 기능과 각 열에 대한 필터링, 정렬, 편집, 이동 및 크기 조정 기능을 활성화합니다.

    <IgbTreeGrid AutoGenerate="false"
                 PrimaryKey="ID"
                 ForeignKey="ParentID"
                 Data="EmployeesFlatDataItem"
                 RowSelection="GridSelectionMode.Multiple"
                 AllowFiltering=true
                 Moving=true
                 Name="treeGrid"
                 @ref="treeGrid">
        <IgbColumn Field="Name" DataType="GridColumnDataType.String" Sortable=true Editable=true Resizable=true></IgbColumn>
        <IgbColumn Field="JobTitle" DataType="GridColumnDataType.String" Sortable=true Editable=true Resizable=true></IgbColumn>
        <IgbColumn Field="Age" DataType="GridColumnDataType.Number" Sortable=true Editable=true Resizable=true> </IgbColumn>
    </IgbTreeGrid>
    

    최종 결과는 다음과 같습니다.

    Persistence and Integration

    트리 그리드 셀의 들여쓰기는 필터링, 정렬 및 페이징과 같은 다른 트리 그리드 기능에서 유지됩니다.

    • When Sorting is applied on a column, the data rows get sorted by levels. This means that the root level rows will be sorted independently from their respective children. Their respective children collections will each be sorted independently as well and so on.
    • The first column (the one that has a VisibleIndex of 0) is always the tree column.
    • The column that ends up with a VisibleIndex of 0 after operations like column pinning, column hiding and column moving becomes the tree column.
    • 내보낸 Excel 워크시트는 트리 그리드 자체에 그룹화된 레코드를 그룹화하여 계층 구조를 반영합니다. 모든 레코드 확장 상태도 유지되고 반영됩니다.
    • CSV로 내보낼 때 레벨 및 확장 상태가 무시되고 모든 데이터가 플랫으로 내보내집니다.

    Blazor Tree Grid Styling Configuration

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

    <IgbTreeGrid Class="tree-grid">
    

    그런 다음 해당 클래스에 대한 관련 CSS 속성을 설정합니다.

    .tree-grid {
        --ig-grid-header-background: #494949;
        --ig-grid-header-text-color: #FFF;
        --ig-grid-expand-icon-color: #FFCD0F;
        --ig-grid-expand-icon-hover-color: #E0B710;
        --ig-grid-row-hover-background: #F8E495;
    }
    

    API References

    Additional Resources

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