-
-
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.
DataGrid: add ExpressionCompiler utility (#5872)
* DataGrid ExpressionCompiler ongoing * ExpressionCompiler | Segregate into Sort | Search | Paging | Improve DataGridPage filter example * Add Expression support for less than or greater than * ExpressionCompiler | Between Support * Docs and Release notes * Add DataGrid ExpressionCompiler support for DataGridReadDataEventArgs<TItem> * Format fix * Fix grammar --------- Co-authored-by: Mladen Macanovic <[email protected]>
- Loading branch information
1 parent
314d97e
commit 6082c85
Showing
11 changed files
with
1,057 additions
and
241 deletions.
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
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> |
Oops, something went wrong.