-
-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b70ffc2
commit a1407b3
Showing
6 changed files
with
226 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...s/Pages/Docs/Extensions/DataGrid/Code/DataGridLargeDataExpressionCompilerExampleCode.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<div class="blazorise-codeblock"> | ||
<div class="html"><pre> | ||
<span class="atSign">@</span>using Blazorise.DataGrid.Extensions; | ||
<span class="atSign">@</span>using Blazorise.DataGrid.Utils | ||
|
||
<span class="htmlTagDelimiter"><</span><span class="htmlElementName">DataGrid</span> <span class="htmlAttributeName"><span class="atSign">@</span>ref</span><span class="htmlOperator">=</span><span class="htmlAttributeValue">dataGridRef</span> | ||
<span class="htmlAttributeName">TItem</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue">Employee</span><span class="quot">"</span> | ||
<span class="htmlAttributeName">Data</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="sharpVariable"><span class="atSign">@</span>employeeList</span><span class="quot">"</span> | ||
<span class="htmlAttributeName">ReadData</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="sharpVariable"><span class="atSign">@</span>OnReadData</span><span class="quot">"</span> | ||
<span class="htmlAttributeName">TotalItems</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="sharpVariable"><span class="atSign">@</span>totalEmployees</span><span class="quot">"</span> | ||
<span class="htmlAttributeName">PageSize</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue">10</span><span class="quot">"</span> | ||
<span class="htmlAttributeName">ShowPager</span> | ||
<span class="htmlAttributeName">Responsive</span> | ||
<span class="htmlAttributeName">Filterable</span> | ||
<span class="htmlAttributeName">FilterMode</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="enum">DataGridFilterMode</span><span class="enumValue">.Menu</span><span class="quot">"</span><span class="htmlTagDelimiter">></span> | ||
<span class="htmlTagDelimiter"><</span><span class="htmlElementName">DataGridCommandColumn</span> <span class="htmlTagDelimiter">/></span> | ||
<span class="htmlTagDelimiter"><</span><span class="htmlElementName">DataGridColumn</span> <span class="htmlAttributeName">Field</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue"><span class="atSign">@</span>nameof(Employee.FirstName)</span><span class="quot">"</span> <span class="htmlAttributeName">Caption</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue">First Name</span><span class="quot">"</span> <span class="htmlAttributeName">Editable</span> <span class="htmlTagDelimiter">/></span> | ||
<span class="htmlTagDelimiter"><</span><span class="htmlElementName">DataGridColumn</span> <span class="htmlAttributeName">Field</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue"><span class="atSign">@</span>nameof(Employee.LastName)</span><span class="quot">"</span> <span class="htmlAttributeName">Caption</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue">Last Name</span><span class="quot">"</span> <span class="htmlAttributeName">Editable</span> <span class="htmlTagDelimiter">/></span> | ||
<span class="htmlTagDelimiter"><</span><span class="htmlElementName">DataGridSelectColumn</span> <span class="htmlAttributeName">TItem</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue">Employee</span><span class="quot">"</span> <span class="htmlAttributeName">Field</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue"><span class="atSign">@</span>nameof( Employee.Gender )</span><span class="quot">"</span> <span class="htmlAttributeName">Caption</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue">Gender</span><span class="quot">"</span> <span class="htmlAttributeName">Editable</span> <span class="htmlAttributeName">Data</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="enum">EmployeeData</span><span class="enumValue">.Genders</span><span class="quot">"</span> <span class="htmlAttributeName">ValueField</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue">(x) => ((Gender)x).Code</span><span class="quot">"</span> <span class="htmlAttributeName">TextField</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue">(x) => ((Gender)x).Description</span><span class="quot">"</span> <span class="htmlTagDelimiter">/></span> | ||
<span class="htmlTagDelimiter"><</span><span class="htmlElementName">DataGridNumericColumn</span> <span class="htmlAttributeName">Field</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue"><span class="atSign">@</span>nameof( Employee.Childrens )</span><span class="quot">"</span> <span class="htmlAttributeName">Caption</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue">Childrens</span><span class="quot">"</span> <span class="htmlAttributeName">Editable</span> <span class="htmlTagDelimiter">/></span> | ||
<span class="htmlTagDelimiter"><</span><span class="htmlElementName">DataGridDateColumn</span> <span class="htmlAttributeName">Field</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue"><span class="atSign">@</span>nameof( Employee.DateOfBirth )</span><span class="quot">"</span> <span class="htmlAttributeName">DisplayFormat</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue">{0:dd.MM.yyyy}</span><span class="quot">"</span> <span class="htmlAttributeName">Caption</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue">Date Of Birth</span><span class="quot">"</span> <span class="htmlAttributeName">Editable</span> <span class="htmlTagDelimiter">/></span> | ||
<span class="htmlTagDelimiter"></</span><span class="htmlElementName">DataGrid</span><span class="htmlTagDelimiter">></span> | ||
</pre></div> | ||
<div class="csharp"><pre> | ||
<span class="atSign">@</span>code { | ||
[Inject] <span class="keyword">public</span> EmployeeData EmployeeData { <span class="keyword">get</span>; <span class="keyword">set</span>; } | ||
<span class="keyword">private</span> DataGrid<Employee> dataGridRef; | ||
<span class="keyword">private</span> List<Employee> employeeListSource; | ||
<span class="keyword">private</span> List<Employee> employeeList; | ||
|
||
<span class="keyword">protected</span> <span class="keyword">override</span> <span class="keyword">async</span> Task OnInitializedAsync() | ||
{ | ||
employeeListSource = <span class="keyword">await</span> EmployeeData.GetDataAsync(); | ||
<span class="keyword">await</span> <span class="keyword">base</span>.OnInitializedAsync(); | ||
} | ||
|
||
<span class="keyword">private</span> <span class="keyword">int</span> totalEmployees; | ||
|
||
<span class="keyword">private</span> <span class="keyword">async</span> Task OnReadData(DataGridReadDataEventArgs<Employee> e) | ||
{ | ||
|
||
<span class="keyword">if</span> (!e.CancellationToken.IsCancellationRequested) | ||
{ | ||
<span class="keyword">var</span> query = employeeListSource.AsQueryable().ApplyDataGridSort(e.Columns).ApplyDataGridSearch(e.Columns); | ||
|
||
<span class="keyword">if</span> (dataGridRef.CustomFilter <span class="keyword">is</span> not <span class="keyword">null</span>) | ||
query = query.Where(item => item != <span class="keyword">null</span> && dataGridRef.CustomFilter(item)); | ||
|
||
<span class="keyword">var</span> response = <span class="keyword">new</span> List<Employee>(); | ||
|
||
<span class="keyword">if</span> (e.ReadDataMode <span class="keyword">is</span> DataGridReadDataMode.Virtualize) | ||
response = query.ApplyDataGridPaging(e.VirtualizeOffset + <span class="number">1</span>, e.VirtualizeCount).ToList(); | ||
<span class="keyword">else</span> <span class="keyword">if</span> (e.ReadDataMode <span class="keyword">is</span> DataGridReadDataMode.Paging) | ||
response = query.ApplyDataGridPaging(e.Page, e.PageSize).ToList(); | ||
<span class="keyword">else</span> | ||
<span class="keyword">throw</span> <span class="keyword">new</span> Exception(<span class="string">"Unhandled ReadDataMode"</span>); | ||
|
||
<span class="keyword">await</span> Task.Delay(Random.Shared.Next(<span class="number">100</span>)); | ||
|
||
<span class="keyword">if</span> (!e.CancellationToken.IsCancellationRequested) | ||
{ | ||
totalEmployees = query.Count(); | ||
employeeList = response; | ||
} | ||
} | ||
} | ||
} | ||
</pre></div> | ||
</div> |
65 changes: 65 additions & 0 deletions
65
.../Pages/Docs/Extensions/DataGrid/Examples/DataGridLargeDataExpressionCompilerExample.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
@using Blazorise.DataGrid.Extensions; | ||
@using Blazorise.DataGrid.Utils | ||
@namespace Blazorise.Docs.Docs.Examples | ||
|
||
<DataGrid @ref=dataGridRef | ||
TItem="Employee" | ||
Data="@employeeList" | ||
ReadData="@OnReadData" | ||
TotalItems="@totalEmployees" | ||
PageSize="10" | ||
ShowPager | ||
Responsive | ||
Filterable | ||
FilterMode="DataGridFilterMode.Menu"> | ||
<DataGridCommandColumn /> | ||
<DataGridColumn Field="@nameof(Employee.FirstName)" Caption="First Name" Editable /> | ||
<DataGridColumn Field="@nameof(Employee.LastName)" Caption="Last Name" Editable /> | ||
<DataGridSelectColumn TItem="Employee" Field="@nameof( Employee.Gender )" Caption="Gender" Editable Data="EmployeeData.Genders" ValueField="(x) => ((Gender)x).Code" TextField="(x) => ((Gender)x).Description" /> | ||
<DataGridNumericColumn Field="@nameof( Employee.Childrens )" Caption="Childrens" Editable /> | ||
<DataGridDateColumn Field="@nameof( Employee.DateOfBirth )" DisplayFormat="{0:dd.MM.yyyy}" Caption="Date Of Birth" Editable /> | ||
</DataGrid> | ||
|
||
@code { | ||
[Inject] public EmployeeData EmployeeData { get; set; } | ||
private DataGrid<Employee> dataGridRef; | ||
private List<Employee> employeeListSource; | ||
private List<Employee> employeeList; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
employeeListSource = await EmployeeData.GetDataAsync(); | ||
await base.OnInitializedAsync(); | ||
} | ||
|
||
private int totalEmployees; | ||
|
||
private async Task OnReadData(DataGridReadDataEventArgs<Employee> e) | ||
{ | ||
|
||
if (!e.CancellationToken.IsCancellationRequested) | ||
{ | ||
var query = employeeListSource.AsQueryable().ApplyDataGridSort(e.Columns).ApplyDataGridSearch(e.Columns); | ||
|
||
if (dataGridRef.CustomFilter is not null) | ||
query = query.Where(item => item != null && dataGridRef.CustomFilter(item)); | ||
|
||
var response = new List<Employee>(); | ||
|
||
if (e.ReadDataMode is DataGridReadDataMode.Virtualize) | ||
response = query.ApplyDataGridPaging(e.VirtualizeOffset + 1, e.VirtualizeCount).ToList(); | ||
else if (e.ReadDataMode is DataGridReadDataMode.Paging) | ||
response = query.ApplyDataGridPaging(e.Page, e.PageSize).ToList(); | ||
else | ||
throw new Exception("Unhandled ReadDataMode"); | ||
|
||
await Task.Delay(Random.Shared.Next(100)); | ||
|
||
if (!e.CancellationToken.IsCancellationRequested) | ||
{ | ||
totalEmployees = query.Count(); | ||
employeeList = response; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters