Blazor 그리드 요약

    Blazor Grid의 Ignite UI for Blazor 열별 수준에서 그룹 바닥글로 작동합니다. Blazor IgbGrid 요약은 열 내의 데이터 유형에 따라 또는 IgbGrid에서 사용자 지정 템플릿을 구현하여 사용자가 미리 정의된 기본 요약 항목 집합이 있는 별도의 컨테이너에서 열 정보를 볼 수 있도록 하는 강력한 기능입니다.

    Blazor Grid Summaries Overview Example

    [!Note] The summary of the column is a function of all column values, unless filtering is applied, then the summary of the column will be function of the filtered result values

    IgbGrid 요약은 Ignite UI for Blazor의 열별 수준에서 활성화할 수도 있습니다. 즉, 필요한 열에 대해서만 활성화할 수 있습니다. IgbGrid 요약은 열의 데이터 유형에 따라 사전 정의된 기본 요약 세트를 제공하므로 시간을 절약할 수 있습니다.

    stringboolean DataType의 경우 다음 함수를 사용할 수 있습니다.

    • 세다

    number, currencypercent 데이터 유형의 경우 다음 함수를 사용할 수 있습니다.

    • 세다
    • 최소
    • 맥스
    • 평균
    • 합집합

    date 데이터 유형의 경우 다음 기능을 사용할 수 있습니다.

    • 세다
    • 가장 빠른
    • 최신

    사용 가능한 모든 열 데이터 유형은 공식 열 유형 항목에서 찾을 수 있습니다.

    IgbGrid 요약은 다음 설정을 통해 열별로 활성화됩니다. HasSummary 재산 진실. 각 열의 요약은 열 데이터 유형에 따라 결정된다는 점을 명심하는 것도 중요합니다. 에서 IgbGrid 기본 열 데이터 유형은 다음과 같습니다. string, 그러니 원한다면 number 또는 date 특정 요약을 지정해야 합니다. DataType 재산 number 또는 date. 요약 값은 그리드에 따라 현지화되어 표시됩니다. Locale 및 열 PipeArgs.

    <IgbGrid>
            <IgbColumn Field="EmployeeID" DataType="GridColumnDataType.Number" HasSummary="true"></IgbColumn>
            <IgbColumn Field="FirstName" HasSummary="true"></IgbColumn>
            <IgbColumn Field="LastName" HasSummary="true"></IgbColumn>
            <IgbColumn Field="Title" HasSummary="true"></IgbColumn>
    </IgbGrid>
    

    특정 열이나 열 목록에 대한 요약을 활성화/비활성화하는 다른 방법은 IgbGrid의 공개 메서드 EnableSummaries / DisableSummaries 사용하는 것입니다.

     <IgbGrid @ref=grid Id="grid" AutoGenerate="false">
            <IgbColumn Field="EmployeeID" DataType="GridColumnDataType.Number" HasSummary="true"></IgbColumn>
            <IgbColumn Field="FirstName" Sortable="true" HasSummary="true"></IgbColumn>
            <IgbColumn Field="LastName" Sortable="false" DisablePinning="true" DisableHiding="true" HasSummary="true"></IgbColumn>
            <IgbColumn Field="Title" Sortable="true" DisablePinning="false" DisableHiding="true"></IgbColumn>
    </IgbGrid>
    
    @code {
        public async void DisableSummaries()
        {
            object[] disabledSummaries = { "EmployeeID" };
            await this.grid.DisableSummariesAsync(disabledSummaries);
        }
    }
    

    Custom Grid Summaries

    이러한 기능이 요구 사항을 충족하지 못하는 경우 특정 열에 대한 사용자 정의 요약을 제공할 수 있습니다.

    
    //In JavaScript
    class WebGridDiscontinuedSummary {
        operate(data, allData, fieldName) {
            const discontinuedData = allData.filter((rec) => rec['Discontinued']).map(r => r[fieldName]);
            const result = [];
            result.push({
                key: 'products',
                label: 'Products',
                summaryResult: data.length
            });
            result.push({
                key: 'total',
                label: 'Total Items',
                summaryResult: data.length ? data.reduce((a, b) => +a + +b) : 0
            });
            result.push({
                key: 'discontinued',
                label: 'Discontinued Products',
                summaryResult: allData.map(r => r['Discontinued']).filter((rec) => rec).length
            });
            result.push({
                key: 'totalDiscontinued',
                label: 'Total Discontinued Items',
                summaryResult: discontinuedData.length ? discontinuedData.reduce((a, b) => +a + +b) : 0
            });
            return result;
        }
    }
    

    예제에서 볼 수 있듯이 기본 클래스는 Operate 메서드를 노출하므로 모든 기본 요약을 가져오고 결과를 수정하거나 완전히 새로운 요약 결과를 계산하도록 선택할 수 있습니다.

    이 메소드는 IgbSummaryResult 목록을 반환합니다.

    요약을 계산하기 위해 선택적 매개변수를 사용합니다. 아래의 모든 데이터 섹션에 액세스하는 사용자 정의 요약을 참조하세요.

    [!Note] In order to calculate the summary row height properly, the Grid needs the Operate method to always return an array of IgbSummaryResult with the proper length even when the data is empty.

    <IgbGrid 
            AutoGenerate="true"
            Name="grid"
            @ref="grid"
            Data="NwindData"
            PrimaryKey="ProductID"
            ColumnInitScript="WebGridCustomSummary">
    </IgbGrid>
    
    // In Javascript
    igRegisterScript("WebGridCustomSummary", (event) => {
        if (event.detail.field === "UnitsInStock") {
            event.detail.summaries = WebGridDiscontinuedSummary;
        }
    }, false);
    

    Custom summaries, which access all data

    이제 사용자 정의 열 요약 내의 모든 그리드 데이터에 액세스할 수 있습니다. SummaryOperand Operate 메서드에는 두 개의 추가 선택적 매개 변수가 도입되었습니다. 아래 코드 조각에서 볼 수 있듯이 Operate 메소드에는 다음 세 가지 매개변수가 있습니다.

    • columnData - 현재 열의 값만 포함하는 배열을 제공합니다.
    • allGridData - 전체 그리드 데이터 소스를 제공합니다.
    • fieldName - 현재 열 필드
    class WebGridDiscontinuedSummary {
        operate(data, allData, fieldName) {
            const discontinuedData = allData.filter((rec) => rec['Discontinued']).map(r => r[fieldName]);
            result.push({
                key: 'totalDiscontinued',
                label: 'Total Discontinued Items',
                summaryResult: discontinuedData.length ? discontinuedData.reduce((a, b) => +a + +b) : 0
            });
            return result;
        }
    }
    

    Summary Template

    Summary 열 요약 결과를 컨텍스트로 제공하는 열 요약을 대상으로 합니다.

    <IgbColumn HasSummary="true" SummaryTemplateScript="SummaryTemplate">
    </IgbColumn>
    
    igRegisterScript("SummaryTemplate", (ctx) => {
        var html = window.igTemplating.html;
        return html`<div>
        <span> ${ctx.implicit[0].label} - ${ctx.implicit[0].summaryResult} </span>
    </div>`
    }, false);
    

    기본 요약이 정의되면 요약 영역의 높이는 요약 수가 가장 많은 열과 그리드의 표시 밀도에 따라 설계에 따라 계산됩니다. 기본값을 대체하려면 SummaryRowHeight 입력 특성을 사용하십시오. 인수로 숫자 값이 필요하며 잘못된 값을 설정하면 그리드 바닥글의 기본 크기 조정 동작이 트리거됩니다.

    Formatting summaries

    기본적으로, 기본 제공 요약 피연산자에 의해 생성된 요약 결과는 그리드 Locale와 열 PipeArgs에 따라 지역화되고 형식이 지정됩니다. 사용자 정의 피연산자를 Locale 사용하는 경우 및 PipeArgs는 적용되지 않습니다. 요약 결과의 기본 모양을 변경하려면 속성을 사용하여 SummaryFormatter 형식을 지정할 수 있습니다.

    <IgbColumn HasSummary="true" SummaryFormatterScript="SummaryFormatter"/>
    
    igRegisterScript("SummaryFormatter", (summary) => {
        const result = summary.summaryResult;
        if (summaryOperand instanceof IgcDateSummaryOperand && summary.key !== "count" && result !== null && result !== undefined) {
            const format = new Intl.DateTimeFormat("en", { year: "numeric" });
            return format.format(new Date(result));
        }
        return result;
    }, true);
    

    Summaries with Group By

    열별로 그룹화한 경우 IgbGrid 사용하면 SummaryCalculationModeSummaryPosition 속성을 사용하여 요약 위치와 계산 모드를 변경할 수 있습니다. 이 두 속성과 함께 IgbGrid 참조하는 그룹 행이 축소될 때 요약 행이 계속 표시되는지 여부를 결정할 수 있는 ShowSummaryOnCollapse 속성을 노출합니다.

    SummaryCalculationMode 속성의 사용 가능한 값은 다음과 같습니다.

    • RootLevelOnly- 요약은 루트 수준에 대해서만 계산됩니다.
    • ChildLevelsOnly- 요약은 하위 수준에 대해서만 계산됩니다.
    • RootAndChildLevels- 루트 및 하위 수준 모두에 대한 요약이 계산됩니다. 이것이 기본값입니다.

    SummaryPosition 속성의 사용 가능한 값은 다음과 같습니다.

    • Top- 요약 행이 그룹별 하위 항목 앞에 나타납니다.
    • Bottom- 요약 행은 행 하위 그룹별로 표시됩니다. 이것이 기본값입니다.

    ShowSummaryOnCollapse 속성은 부울입니다. 기본값은 false로 설정됩니다. 즉, 그룹 행이 축소되면 요약 행이 숨겨집니다. 속성이 true로 설정되면 그룹 행이 축소될 때 요약 행이 계속 표시됩니다.

    [!Note] The SummaryPosition property applies only for the child level summaries. The root level summaries appear always fixed at the bottom of the IgbGrid.

    Demo

    Keyboard Navigation

    요약 행은 다음 키보드 상호 작용을 통해 탐색할 수 있습니다.

    • UP- 한 셀 위로 이동합니다.
    • DOWN- 한 셀 아래로 이동합니다.
    • 왼쪽- 한 셀 왼쪽으로 이동합니다.
    • RIGHT- 한 셀 오른쪽으로 이동합니다.
    • CTRL + LEFT 또는 HOME- 가장 왼쪽 셀로 이동합니다.
    • CTRL + RIGHT 또는 END- 가장 오른쪽 셀로 이동합니다.

    Styling

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

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

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

    .grid {
        --ig-grid-summary-background-color:#e0f3ff;
        --ig-grid-summary-focus-background-color: rgba( #94d1f7, .3 );
        --ig-grid-summary-label-color: rgb(228, 27, 117);
        --ig-grid-summary-result-color: black;
    }
    

    Demo

    API References

    Additional Resources

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