Blazor Grid 요약
Blazor 그리드의 Ignite UI for Blazor 요약 기능은 각 열별로 그룹 푸터로 기능합니다. IgbGrid 요약 Blazor 강력한 기능으로, 사용자가 열 내 데이터 유형에 따라 또는 사용자 지정 템플릿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, 다음과 같은 함수가 제공됩니다:
- 세다
데이터 유형에 대해서는numbercurrencypercent 다음과 같은 함수들이 제공됩니다:
- 세다
- 최소
- 맥스
- 평균
- 합집합
데이터 타입의 경우date, 다음과 같은 함수들이 제공됩니다:
- 세다
- 가장 빠른
- 최신
사용 가능한 모든 열 데이터 유형은 공식 열 유형 항목에서 찾을 수 있습니다.
IgbGrid요약은 다음 다음 열별로 활성화됩니다HasSummary property를 참. 각 열의 요약은 열 데이터 유형에 따라 해석된다는 점도 기억하는 것이 중요합니다. 안에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>
특정 열이나 열의 목록에 대한 요약을 활성화하거나 비활성화하는 또 다른 방법은 공개EnableSummaries 메서드DisableSummariesIgbGrid를 사용하는 것입니다.
<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
Operatemethod to always return an array ofIgbSummaryResultwith 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
이제 커스텀 컬럼 요약 안에서 모든 그리드 데이터에 접근할 수 있습니다. SummaryOperandOperate 메서드에는 두 가지 추가 선택 매개변수가 도입되었습니다. 아래 코드 스니펫에서 볼 수 있듯이 연산 메서드는 다음과 같은 세 가지 매개변수를 가집니다:
- 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 해 기본값을 덮어쓰세요. 인수로서 숫자 값을 기대하며, 가짜 값을 설정하면 그리드 푸터의 기본 크기 동작이 촉발됩니다.
Disabled Summaries
이 속성은DisabledSummaries Blazor 그리드 요약 기능에 대해 열별로 정밀한 제어를 제공합니다. 이 특성은 사용자가 IgbGrid의 각 열에 대한 요약을 맞춤화하여 가장 관련성 높고 의미 있는 데이터만 표시하도록 할 수 있게 합니다. 예를 들어, ['count', 'min', 'max']와 같은 특정 요약 유형을 배열에 요약 키를 지정하여 제외할 수 있습니다.
또한 이 속성은 코드를 통해 런타임에 동적으로 수정할 수 있으므로 IgbGrid의 요약을 애플리케이션 상태 또는 사용자 작업 변경에 맞게 유연하게 조정할 수 있습니다.
다음 예시들은 이 속성을 사용하여DisabledSummaries 다양한 열의 요약을 관리하고 Blazor 그리드에서 특정 기본 및 사용자 지정 요약 유형을 제외하는 방법을 보여줍니다:
<!-- 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, 기본 요약 같은count 것들은 비활성화되어 있고,sumaverage 다른 것들은 좋아min 요와max 활성화된 상태로 남아 있습니다.
그리고UnitsInStock 같은 맞춤형 요약discontinuedtotalDiscontinued은 해당 속성을 사용할 때DisabledSummaries 제외됩니다.
런타임에는 이 속성을 사용하여DisabledSummaries 요약을 동적으로 비활성화할 수도 있습니다. 예를 들어, 특정 열의 속성을 프로그래밍적으로 설정하거나 업데이트하여 사용자 행동이나 애플리케이션 상태 변화에 따라 표시되는 요약을 조정할 수 있습니다.
Summaries with Group By
열IgbGrid 별로 그룹화하면 summarySummaryCalculationMode position과 calculation 모드를 and properties를 사용SummaryPosition 해 변경할 수 있습니다. 이 두 속성IgbGrid과 함께 노출 속성ShowSummaryOnCollapse과 속성은 참조하는 그룹 행이 접혔을 때 요약 행이 계속 보이는지 여부를 결정할 수 있게 해줍니다.
부동산의SummaryCalculationMode 이용 가능한 가치는 다음과 같습니다:
RootLevelOnly- 요약은 루트 레벨에만 대해 계산됩니다.ChildLevelsOnly- 요약은 자식 수준에만 적용됩니다.RootAndChildLevels- 요약은 루트 레벨과 자식 레벨 모두에 대해 계산됩니다. 이것이 기본 값입니다.
부동산의SummaryPosition 이용 가능한 가치는 다음과 같습니다:
Top- 요약 행은 행 아이들에 의해 그룹 앞에 나타납니다.Bottom- 요약 행은 행 아이들이 그룹 다음에 나타납니다. 이것이 기본 값입니다.
이 부동산은ShowSummaryOnCollapse 불리언입니다. 기본값은 false로 설정되어 있어, 그룹 행이 붕괴되면 요약 행이 숨겨집니다. 속성이 true로 설정되어 있으면 그룹 행이 접혀도 요약 행은 계속 보이게 됩니다.
[!Note] The
SummaryPositionproperty 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
SummaryOperandNumberSummaryOperandDateSummaryOperandIgbColumnGroupIgbColumn
Additional Resources
우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.