このコントロールは非推奨であり、Grid に置き換えられていることに注意してください。そのため、そのコントロールに移行することをお勧めします。これは新しい機能を受け取ることはなく、バグ修正は優先されません。コードベースをデータ グリッドに移行する際のヘルプや質問については、サポートにお問い合わせください。
Blazor 列集計
Ignite UI for Blazor Data Table / Data Grid は、列集計をサポートしています。エンドユーザーは、グリッドに表示されるデータ量が多い場合などでデータ集計の表示を必要とすることがあります。エンドユーザーは、特定の列のデータから追加情報を取得することもできます。これを実現するには集計が役立ちます。集計を有効にするには、SummaryScope
プロパティを設定します。
すぐに使用できる機能のフルセット は、ページング、ソート、フィルタリング、編集、グループ化から行と列の仮想化まで、あらゆる機能をカバーします。.NET 開発者には制限はありません。
Blazor 列集計の例
EXAMPLE
MODULES
DATA GENERATOR
DATA SOURCE
RAZOR
JS
CSS
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls;
namespace Infragistics.Samples
{
public class Program
{
public static async Task Main (string [] args )
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app" );
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddIgniteUIBlazor(
typeof (IgbDataGridModule),
typeof (IgbGridColumnOptionsModule)
);
await builder.Build().RunAsync();
}
}
}
cs コピー using System;
using System.Collections.Generic;
using System.Linq;
namespace Infragistics.Samples
{
public static class DataGenerator
{
readonly static string [] websites = { ".com" , ".gov" , ".edu" , ".org" };
readonly static string [] emails = { "gmail.com" , "yahoo.com" , "twitter.com" };
readonly static string [] genders = { "male" , "female" };
readonly static string [] maleNames = { "Kyle" , "Oscar" , "Ralph" , "Mike" , "Bill" , "Frank" , "Howard" , "Jack" , "Larry" , "Pete" , "Steve" , "Vince" , "Mark" , "Alex" , "Max" , "Brian" , "Chris" , "Andrew" , "Martin" , "Mike" , "Steve" , "Glenn" , "Bruce" };
readonly static string [] femaleNames = { "Gina" , "Irene" , "Katie" , "Brenda" , "Casey" , "Fiona" , "Holly" , "Kate" , "Liz" , "Pamela" , "Nelly" , "Marisa" , "Monica" , "Anna" , "Jessica" , "Sofia" , "Isabella" , "Margo" , "Jane" , "Audrey" , "Sally" , "Melanie" , "Greta" , "Aurora" , "Sally" };
readonly static string [] lastNames = { "Adams" , "Crowley" , "Ellis" , "Martinez" , "Irvine" , "Maxwell" , "Clark" , "Owens" , "Rooney" , "Lincoln" , "Thomas" , "Spacey" , "MOrgan" , "King" , "Newton" , "Fitzgerald" , "Holmes" , "Jefferson" , "Landry" , "Berry" , "Perez" , "Spencer" , "Starr" , "Carter" , "Edwards" , "Stark" , "Johnson" , "Fitz" , "Chief" , "Blanc" , "Perry" , "Stone" , "Williams" , "Lane" , "Jobs" , "Adams" , "Power" , "Tesla" };
readonly static string [] countries = { "USA" , "UK" , "France" , "Canada" , "Poland" };
readonly static string [] citiesUS = { "New York" , "Los Angeles" , "Miami" , "San Francisco" , "San Diego" , "Las Vegas" };
readonly static string [] citiesUK = { "London" , "Liverpool" , "Manchester" };
readonly static string [] citiesFR = { "Paris" , "Marseille" , "Lyon" };
readonly static string [] citiesCA = { "Toronto" , "Vancouver" , "Montreal" };
readonly static string [] citiesPL = { "Krakow" , "Warsaw" , "Wroclaw" , "Gdansk" };
readonly static string [] citiesJP = { "Tokyo" , "Osaka" , "Kyoto" , "Yokohama" };
readonly static string [] citiesGR = { "Berlin" , "Bonn" , "Cologne" , "Munich" , "Hamburg" };
readonly static string [] roadSuffixes = { "Road" , "Street" , "Way" };
readonly static string [] roadNames = { "Main" , "Garden" , "Broad" , "Oak" , "Cedar" , "Park" , "Pine" , "Elm" , "Market" , "Hill" };
public static Random Rand = new Random();
public static string GetWebsite ( )
{
return GetItem(websites);
}
public static string GetEmail ( )
{
return GetItem(emails);
}
public static double GetNumber (double min, double max )
{
return Math.Round(min + (Rand.NextDouble() * (max - min)));
}
public static int GetInteger (double min, double max )
{
return (int )GetNumber(min, max);
}
public static string GetPhone ( )
{
var phoneCode = GetNumber(100 , 900 );
var phoneNum1 = GetNumber(100 , 900 );
var phoneNum2 = GetNumber(1000 , 9000 );
var phone = phoneCode + "-" + phoneNum1 + "-" + phoneNum2;
return phone;
}
public static string GetGender ( )
{
return GetItem(genders);
}
public static string GetNameFirst (string gender )
{
if (gender == "male" )
return GetItem(maleNames);
else
return GetItem(femaleNames);
}
public static string GetNameLast ( )
{
return GetItem(lastNames);
}
public static string GetItem (string [] array )
{
var index = (int )Math.Round(GetNumber(0 , array.Length - 1 ));
return array[index];
}
public static string GetCountry ( )
{
return GetItem(countries);
}
public static string GetCity (string country )
{
if (country == "Canada" )
{
return GetItem(citiesCA);
}
else if (country == "France" )
{
return GetItem(citiesFR);
}
else if (country == "Poland" )
{
return GetItem(citiesPL);
}
else if (country == "USA" )
{
return GetItem(citiesUS);
}
else if (country == "Japan" )
{
return GetItem(citiesJP);
}
else if (country == "Germany" )
{
return GetItem(citiesGR);
}
else
{
return GetItem(citiesUK);
}
}
public static string GetStreet ( )
{
var num = Math.Round(GetNumber(100 , 300 )).ToString();
var road = GetItem(roadNames);
var suffix = GetItem(roadSuffixes);
return num + " " + road + " " + suffix;
}
public static DateTime GetBirthday ( )
{
var year = DateTime.Now.Year - GetInteger(30 , 50 );
var month = GetNumber(10 , 12 );
var day = GetNumber(20 , 27 );
return new DateTime(year, (int )month, (int )day);
}
public static DateTime GetDate ( )
{
var year = DateTime.Now.Year;
var month = GetNumber(10 , 12 );
var day = GetNumber(20 , 27 );
return new DateTime(year, (int )month, (int )day);
}
public static string Pad (int num, int size )
{
var s = num + "" ;
while (s.Length < size)
{
s = "0" + s;
}
return s;
}
public static string GetPhotoMale (int id )
{
return "https://static.infragistics.com/xplatform/images/people/GUY" + Pad(id, 2 ) + ".png" ;
}
public static string GetPhotoFemale (int id )
{
return "https://static.infragistics.com/xplatform/images/people/GIRL" + Pad(id, 2 ) + ".png" ;
}
private static int maleCount = 0 ;
private static int femaleCount = 0 ;
public static string GetPhoto (string gender )
{
if (gender == "male" )
{
maleCount++;
if (maleCount > 24 ) maleCount = 1 ;
return GetPhotoMale(maleCount);
}
else
{
femaleCount++;
if (femaleCount > 24 ) femaleCount = 1 ;
return GetPhotoFemale(femaleCount);
}
}
public static string GetGenderPhoto (string gender )
{
return "https://static.infragistics.com/xplatform/images/genders/" + gender + ".png" ;
}
public static string GetCountryFlag (string country )
{
return "https://static.infragistics.com/xplatform/images/flags/" + country + ".png" ;
}
public static string GetIncomeRange (double salary )
{
if (salary < 50000 )
{
return "Low" ;
}
else if (salary < 100000 )
{
return "Average" ;
}
else
{
return "High" ;
}
}
}
}
cs コピー using System;
using System.Collections.Generic;
namespace Infragistics.Samples
{
public class SaleInfo
{
public DateTime OrderDate { get ; set ; }
public string ID { get ; set ; }
public string ProductName { get ; set ; }
public double ProductPrice { get ; set ; }
public double BundlePrice { get ; set ; }
public double Margin { get ; set ; }
public double OrderItems { get ; set ; }
public double OrderValue { get ; set ; }
public double Profit { get ; set ; }
public string Country { get ; set ; }
public string CountryFlag { get ; set ; }
public string City { get ; set ; }
public string Status { get ; set ; }
}
public class SalesDataService
{
public static List<SaleInfo> Create (int ? count )
{
if (count == null ) count = 100 ;
string [] names = {
"Intel CPU" , "AMD CPU" ,
"Intel Motherboard" , "AMD Motherboard" , "NVIDIA Motherboard" ,
"NVIDIA GPU" , "GIGABYTE GPU" , "Asus GPU" , "AMD GPU" , "MSI GPU" ,
"Corsair Memory" , "Patriot Memory" , "Skill Memory" ,
"Samsung HDD" , "WD HDD" , "Seagate HDD" , "Intel HDD" ,
"Samsung SSD" , "WD SSD" , "Seagate SSD" , "Intel SSD" ,
"Samsung Monitor" , "Asus Monitor" , "LG Monitor" , "HP Monitor" };
string [] countries = { "USA" , "UK" , "France" , "Canada" , "Poland" , "Japan" , "Germany" };
string [] status = { "Packing" , "Shipped" , "Delivered" };
var sales = new List<SaleInfo>();
for (var i = 0 ; i < count; i++)
{
var price = DataGenerator.GetNumber(100 , 900 );
var items = DataGenerator.GetNumber(10 , 80 );
var value = price * items;
var margin = DataGenerator.GetNumber(3 , 10 );
var profit = Math.Round((price * margin / 100 ) * items);
var country = DataGenerator.GetItem(countries);
var city = DataGenerator.GetCity(country);
sales.Add(new SaleInfo
{
ID = DataGenerator.Pad(1001 + i, 4 ),
BundlePrice = price,
ProductPrice = price,
Margin = margin,
OrderDate = DataGenerator.GetDate(),
OrderItems = items,
OrderValue = value ,
ProductName = DataGenerator.GetItem(names),
Profit = profit,
City = city,
Country = country,
CountryFlag = DataGenerator.GetCountryFlag(country),
Status = DataGenerator.GetItem(status)
});
}
return sales;
}
}
}
cs コピー
@using IgniteUI.Blazor.Controls
<div class ="container vertical" >
<div class ="options horizontal" >
<span class ="options-item" > Summary Scope:</span >
<select class ="options-item" @bind ="GridSummaryScope" >
<option > @ SummaryScope.Root </option >
<option > @ SummaryScope.Groups </option >
<option > @ SummaryScope.Both </option >
<option > @ SummaryScope.None </option >
</select >
<span class ="options-item" > Group Summary Display Mode:</span >
<select class ="options-item" @bind ="GridGroupSummaryDisplayMode" >
<option > @ GroupSummaryDisplayMode.List </option >
<option > @ GroupSummaryDisplayMode.Cells </option >
<option > @ GroupSummaryDisplayMode.RowTop </option >
<option > @ GroupSummaryDisplayMode.RowBottom </option >
<option > @ GroupSummaryDisplayMode.None </option >
</select >
</div >
<div class ="container vertical" >
@ if (Data != null )
{
<div style ="overflow: hidden" >
<IgbDataGrid Height ="100%" Width ="100%"
@ref ="@ DataGridRef "
SummaryScope ="@ GridSummaryScope "
GroupSummaryDisplayMode ="@ GridGroupSummaryDisplayMode "
AutoGenerateColumns ="false"
IsGroupCollapsable ="true"
GroupHeaderDisplayMode ="@ GroupHeaderDisplayMode.Combined "
IsColumnOptionsEnabled ="true"
DataSource ="Data" >
<IgbNumericColumn Field ="ID" Width ="@( "*>120" ) " HeaderText ="ID" HorizontalAlignment ="@ CellContentHorizontalAlignment.Center " />
<IgbTextColumn Field ="ProductName" Width ="@( "*>130" ) " HeaderText ="Product" />
<IgbNumericColumn Field ="BundlePrice" PositivePrefix ="$" Width ="@( "*>120" ) " ShowGroupingSeparator ="true" HeaderText ="Price" />
<IgbNumericColumn Field ="OrderItems" Width ="@( "*>140" ) " HeaderText ="Orders" />
<IgbNumericColumn Field ="OrderValue" Width ="@( "*>160" ) " ShowGroupingSeparator ="true" HeaderText ="Order Totals" PositivePrefix ="$" />
<IgbDateTimeColumn Field ="OrderDate" Width ="@( "*>150" ) " HeaderText ="Order Date" HorizontalAlignment ="@ CellContentHorizontalAlignment.Right " />
<IgbNumericColumn Field ="Profit" Width ="@( "*>140" ) " ShowGroupingSeparator ="true" HeaderText ="Profit" PositivePrefix ="$" />
<IgbTextColumn Field ="Country" Width ="@( "*>170" ) " HeaderText ="Ship Country" />
</IgbDataGrid >
</div >
}
</div >
</div >
@code {
private List <SaleInfo > Data;
private SummaryScope GridSummaryScope;
private GroupSummaryDisplayMode GridGroupSummaryDisplayMode;
private IgbDataGrid _grid;
private IgbDataGrid DataGridRef
{
get { return _grid; }
set
{
_grid = value ;
this .OnDataGridRef();
StateHasChanged();
}
}
protected override void OnInitialized ( )
{
this .Data = SalesDataService.Create(50 );
this .GridSummaryScope = SummaryScope.Root;
this .GridGroupSummaryDisplayMode = GroupSummaryDisplayMode.RowBottom;
}
private void OnDataGridRef ( )
{
var productGroup = new IgbColumnGroupDescription()
{
Field = "ProductName" ,
DisplayName = "ProductName"
};
var productCount = new IgbColumnSummaryDescription()
{
Field = "ProductName" ,
Operand = DataSourceSummaryOperand.Count
};
var priceMin = new IgbColumnSummaryDescription()
{
Field = "BundlePrice" ,
Operand = DataSourceSummaryOperand.Min
};
var priceMax = new IgbColumnSummaryDescription()
{
Field = "BundlePrice" ,
Operand = DataSourceSummaryOperand.Max
};
var orderSum = new IgbColumnSummaryDescription()
{
Field = "OrderItems" ,
Operand = DataSourceSummaryOperand.Sum
};
var orderValueSum = new IgbColumnSummaryDescription()
{
Field = "OrderValue" ,
Operand = DataSourceSummaryOperand.Sum
};
var orderValueAvg = new IgbColumnSummaryDescription()
{
Field = "OrderValue" ,
Operand = DataSourceSummaryOperand.Average
};
var orderDateMin = new IgbColumnSummaryDescription()
{
Field = "OrderDate" ,
Operand = DataSourceSummaryOperand.Min,
CalculatorDisplayName = "First"
};
var orderDateMax = new IgbColumnSummaryDescription()
{
Field = "OrderDate" ,
Operand = DataSourceSummaryOperand.Max,
CalculatorDisplayName = "Last"
};
var sum1 = new IgbColumnSummaryDescription()
{
Field = "Profit" ,
Operand = DataSourceSummaryOperand.Sum
};
var avg2 = new IgbColumnSummaryDescription()
{
Field = "Profit" ,
Operand = DataSourceSummaryOperand.Average
};
this .DataGridRef.GroupDescriptions.Add(productGroup);
this .DataGridRef.SummaryDescriptions.Add(productCount);
this .DataGridRef.SummaryDescriptions.Add(priceMin);
this .DataGridRef.SummaryDescriptions.Add(priceMax);
this .DataGridRef.SummaryDescriptions.Add(orderSum);
this .DataGridRef.SummaryDescriptions.Add(orderValueSum);
this .DataGridRef.SummaryDescriptions.Add(orderValueAvg);
this .DataGridRef.SummaryDescriptions.Add(orderDateMin);
this .DataGridRef.SummaryDescriptions.Add(orderDateMax);
this .DataGridRef.SummaryDescriptions.Add(sum1);
this .DataGridRef.SummaryDescriptions.Add(avg2);
}
}
razor コピー function onProvideCalculator (grid, args ) {
args.setCalculator(null );
}
igRegisterScript("onProvideCalculator" , onProvideCalculator, false );
js コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Blazorツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
SummaryScope プロパティ
グリッドでは、SummaryScope
プロパティを使用して、構成できる4つの集計設定をサポートします。集計設定は以下のとおりです。
Root
: 集計が適用される列にグリッド全体の行の総計を表示します。
Groups
: これはグループ化された行に対して有効です。特定のグループ内の行の総計を表示します。
Both
: Groups
と Root
オプションを同時に使用します。
None
: グリッドの集計を無効にします。
GroupSummaryDisplayMode プロパティ
グリッドは、集計が表示される場所の構成をサポートします。これを構成するには、GroupSummaryDisplayMode
プロパティを使用します。このプロパティのオプションは以下のとおりです。
List : グループ集計をスパン グループ ヘッダーのフラット リストにレンダリングします。
Cells : グループ ヘッダーをセルとしてレンダリングし、集計値を対応する列に揃えてセル内にレンダリングします。グリッドは、このオプションを使用して列ごとに 1 つの集計のみを表示します。
RowTop : グループ集計をグループの上部に集計行としてレンダリングします。
RowBottom : グループ集計をグループの下部に集計行としてレンダリングします。
None : グループ集計のレンダリングを無効にします。
コード スニペット
<IgbDataGrid Height ="500px" Width ="100%"
@ref ="DataGridRef"
SummaryScope ="DataSourceSummaryScope.Root"
GroupSummaryDisplayMode ="GroupSummaryDisplayMode.RowTop"
AutoGenerateColumns ="false"
IsGroupCollapsable ="true"
GroupHeaderDisplayMode ="DataSourceSectionHeaderDisplayMode.Combined"
DataSource ="DataSource" >
<IgbTextColumn Field ="ProductName" Width ="130" HeaderText ="Product" />
<IgbNumericColumn Field ="BundlePrice" PositivePrefix ="$" Width ="120" ShowGroupingSeparator ="true" HeaderText ="Price" />
<IgbNumericColumn Field ="OrderItems" Width ="140" HeaderText ="Orders" />
<IgbNumericColumn Field ="OrderValue" Width ="160" ShowGroupingSeparator ="true" HeaderText ="Order Totals" PositivePrefix ="$" />
<IgbTextColumn Field ="Country" Width ="170" HeaderText ="Ship Country" />
</IgbDataGrid >
@code {
private IgbDataGrid grid;
private IgbDataGrid DataGridRef
{
get { return grid; }
set
{
grid = value ;
this .OnDataGridRef();
StateHasChanged();
}
}
private void OnDataGridRef ( )
{
var productCount = new ColumnSummaryDescription() { Field = "ProductName" , Operand = SummaryOperand.Count };
var priceMin = new ColumnSummaryDescription() { Field = "BundlePrice" , Operand = SummaryOperand.Min };
var priceMax = new ColumnSummaryDescription() { Field = "BundlePrice" , Operand = SummaryOperand.Max };
var orderSum = new ColumnSummaryDescription() { Field = "OrderItems" , Operand = SummaryOperand.Sum };
var orderValueAvg = new ColumnSummaryDescription() { Field = "OrderValue" , Operand = SummaryOperand.Average };
this .DataGridRef.SummaryDescriptions.Add(productCount);
this .DataGridRef.SummaryDescriptions.Add(priceMin);
this .DataGridRef.SummaryDescriptions.Add(priceMax);
this .DataGridRef.SummaryDescriptions.Add(orderSum);
this .DataGridRef.SummaryDescriptions.Add(orderValueAvg);
}
}
razor
API リファレンス