Blazor Grid 요약
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
요약은 열의 데이터 유형에 따라 미리 정의된 기본 요약 세트를 제공하므로 시간을 절약할 수 있습니다.
string
및 boolean
DataType
의 경우 다음 함수를 사용할 수 있습니다.
- 세다
number
, currency
및 percent
데이터 유형의 경우 다음 함수를 사용할 수 있습니다.
- 세다
- 최소
- 맥스
- 평균
- 합집합
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 ofIgbSummaryResult
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
SummaryTemplate
열 요약 결과를 컨텍스트로 제공하는 열 요약을 대상으로 합니다.
<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);
기본 요약이 정의되면 요약 영역의 높이는 요약 수가 가장 많은 열과--ig-size
그리드에 따라 설계에 따라 계산됩니다. SummaryRowHeight
input 속성을 사용하여 기본값을 재정의합니다. 인수로 숫자 값이 필요하며 거짓 값을 설정하면 그리드 바닥글의 기본 크기 조정 동작이 트리거됩니다.
Disabled Summaries
이 DisabledSummaries
속성은 Blazor Grid 요약 기능에 대한 열별 정확한 제어를 제공합니다. 이 속성을 사용하면 사용자가 IgbGrid의 각 열에 대해 표시되는 요약을 사용자 지정하여 가장 관련성이 높고 의미 있는 데이터만 표시되도록 할 수 있습니다. 예를 들어, 배열에서 요약 키를 지정하는 것과 같이 ['count', 'min', 'max']
특정 요약 유형을 제외할 수 있습니다.
또한 이 속성은 코드를 통해 런타임에 동적으로 수정할 수 있으므로 IgbGrid의 요약을 애플리케이션 상태 또는 사용자 작업 변경에 맞게 유연하게 조정할 수 있습니다.
다음 예제에서는 속성을 사용하여 DisabledSummaries
여러 열에 대한 요약을 관리하고 Blazor Grid에서 특정 기본 및 사용자 지정 요약 유형을 제외하는 방법을 보여 줍니다.
<!-- Disable default summaries -->
<IgbColumn
Field="UnitPrice"
Header="Unit Price"
DataType="GridColumnDataType.Number"
HasSummary="true"
DisabledSummaries="['count', 'sum', 'average']" />
<!-- Disable custom summaries -->
<IgbColumn
Field="UnitsInStock"
Header="Units In Stock"
DataType="GridColumnDataType.Number"
HasSummary="true"
Summaries="discontinuedSummary"
DisabledSummaries="['discontinued', 'totalDiscontinued']" />
의 UnitPrice
경우, 기본 요약은 , sum
와 average
같고 count
비활성화되어 있으며 다른 요약은 같고 min
max
활성 상태로 유지됩니다.
의 경우 UnitsInStock
, 및 totalDiscontinued
와 같은 discontinued
사용자 지정 요약은 DisabledSummaries
속성을 사용하여 제외됩니다.
런타임에는 속성을 사용하여 요약을 동적으로 비활성화할 수도 있습니다 DisabledSummaries
. 예를 들어 프로그래밍 방식으로 특정 열의 속성을 설정하거나 업데이트하여 사용자 작업 또는 응용 프로그램 상태 변경에 따라 표시되는 요약을 조정할 수 있습니다.
Summaries with Group By
열별로 그룹화한 경우 IgbGrid
사용하면 SummaryCalculationMode
및 SummaryPosition
속성을 사용하여 요약 위치와 계산 모드를 변경할 수 있습니다. 이 두 속성과 함께 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 theIgbGrid
.
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
SummaryOperand
NumberSummaryOperand
DateSummaryOperand
IgbColumnGroup
IgbColumn
Additional Resources
우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.