Skip to content

Commit

Permalink
Docs and Release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Moreira committed Nov 30, 2024
1 parent b70ffc2 commit a1407b3
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ private async Task OnReadData( DataGridReadDataEventArgs<Employee> e )

var response = new List<Employee>();

//this can be call to anything, in this case we're calling a fictional api


if ( e.ReadDataMode is DataGridReadDataMode.Virtualize )
response = query.ApplyDataGridPaging( e.VirtualizeOffset + 1, e.VirtualizeCount ).ToList();
else if ( e.ReadDataMode is DataGridReadDataMode.Paging )
Expand Down
65 changes: 65 additions & 0 deletions Documentation/Blazorise.Docs/Models/Snippets.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8461,6 +8461,71 @@ private async Task OnReadData( DataGridReadDataEventArgs<Employee> e )
}
}";

public const string DataGridLargeDataExpressionCompilerExample = @"@using Blazorise.DataGrid.Extensions;
@using Blazorise.DataGrid.Utils

<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;
}
}
}
}";

public const string DataGridLoadingEmptyTemplateExample = @"<DataGrid @ref=""datagridRef""
TItem=""Employee""
Data=""@employeeList""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
<DocsPageSectionSource Code="DataGridLargeDataExample" />
</DocsPageSection>

<DocsPageSection>
<DocsPageSectionHeader Title="Expression Compiler">
<Paragraph>
This utility allows you to compile expressions and use them in conjuction with the <Code>DataGrid</Code> <Code>ReadData</Code>, in order to build an <Code>IQueryable</Code> that can be used to query your data.
The <Code>ExpressionCompiler</Code> can be used together with the <Code>DataGridColumnInfo</Code> collection provided by the <Code>ReadData</Code> in order to create Expression based queries (IQueryables) that can in turn be used in ORMs like Entity Framework.
</Paragraph>
</DocsPageSectionHeader>
<DocsPageSectionContent FullWidth Outlined>
<DataGridLargeDataExpressionCompilerExample />
</DocsPageSectionContent>
<DocsPageSectionSource Code="DataGridLargeDataExpressionCompilerExample" />
</DocsPageSection>

<DocsPageApi>
<DocsPageApiItem Url="docs/extensions/datagrid/api" Name="<DataGrid />" />
</DocsPageApi>
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">&#64;</span>using Blazorise.DataGrid.Extensions;
<span class="atSign">&#64;</span>using Blazorise.DataGrid.Utils

<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">DataGrid</span> <span class="htmlAttributeName"><span class="atSign">&#64;</span>ref</span><span class="htmlOperator">=</span><span class="htmlAttributeValue">dataGridRef</span>
<span class="htmlAttributeName">TItem</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue">Employee</span><span class="quot">&quot;</span>
<span class="htmlAttributeName">Data</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="sharpVariable"><span class="atSign">&#64;</span>employeeList</span><span class="quot">&quot;</span>
<span class="htmlAttributeName">ReadData</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="sharpVariable"><span class="atSign">&#64;</span>OnReadData</span><span class="quot">&quot;</span>
<span class="htmlAttributeName">TotalItems</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="sharpVariable"><span class="atSign">&#64;</span>totalEmployees</span><span class="quot">&quot;</span>
<span class="htmlAttributeName">PageSize</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue">10</span><span class="quot">&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">&quot;</span><span class="enum">DataGridFilterMode</span><span class="enumValue">.Menu</span><span class="quot">&quot;</span><span class="htmlTagDelimiter">&gt;</span>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">DataGridCommandColumn</span> <span class="htmlTagDelimiter">/&gt;</span>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">DataGridColumn</span> <span class="htmlAttributeName">Field</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue"><span class="atSign">&#64;</span>nameof(Employee.FirstName)</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Caption</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue">First Name</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Editable</span> <span class="htmlTagDelimiter">/&gt;</span>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">DataGridColumn</span> <span class="htmlAttributeName">Field</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue"><span class="atSign">&#64;</span>nameof(Employee.LastName)</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Caption</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue">Last Name</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Editable</span> <span class="htmlTagDelimiter">/&gt;</span>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">DataGridSelectColumn</span> <span class="htmlAttributeName">TItem</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue">Employee</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Field</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue"><span class="atSign">&#64;</span>nameof( Employee.Gender )</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Caption</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue">Gender</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Editable</span> <span class="htmlAttributeName">Data</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="enum">EmployeeData</span><span class="enumValue">.Genders</span><span class="quot">&quot;</span> <span class="htmlAttributeName">ValueField</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue">(x) =&gt; ((Gender)x).Code</span><span class="quot">&quot;</span> <span class="htmlAttributeName">TextField</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue">(x) =&gt; ((Gender)x).Description</span><span class="quot">&quot;</span> <span class="htmlTagDelimiter">/&gt;</span>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">DataGridNumericColumn</span> <span class="htmlAttributeName">Field</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue"><span class="atSign">&#64;</span>nameof( Employee.Childrens )</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Caption</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue">Childrens</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Editable</span> <span class="htmlTagDelimiter">/&gt;</span>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">DataGridDateColumn</span> <span class="htmlAttributeName">Field</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue"><span class="atSign">&#64;</span>nameof( Employee.DateOfBirth )</span><span class="quot">&quot;</span> <span class="htmlAttributeName">DisplayFormat</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue">{0:dd.MM.yyyy}</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Caption</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue">Date Of Birth</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Editable</span> <span class="htmlTagDelimiter">/&gt;</span>
<span class="htmlTagDelimiter">&lt;/</span><span class="htmlElementName">DataGrid</span><span class="htmlTagDelimiter">&gt;</span>
</pre></div>
<div class="csharp"><pre>
<span class="atSign">&#64;</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&lt;Employee&gt; dataGridRef;
<span class="keyword">private</span> List&lt;Employee&gt; employeeListSource;
<span class="keyword">private</span> List&lt;Employee&gt; 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&lt;Employee&gt; 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 =&gt; item != <span class="keyword">null</span> &amp;&amp; dataGridRef.CustomFilter(item));

<span class="keyword">var</span> response = <span class="keyword">new</span> List&lt;Employee&gt;();

<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">&quot;Unhandled ReadDataMode&quot;</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>
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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@
You may now allow multiple values to be selected in the <Code>DataGridSelectColumn</Code>. Set the new <Code>Multiple</Code> parameter to <Code>true</Code> to enable this feature. Please bind the corresponding array to successfully bind the multiple values.
</Paragraph>

<Heading Size="HeadingSize.Is4">
ExpressionCompiler
</Heading>

<Paragraph>
A new DataGrid utility, the <Code>ExpressionCompiler</Code> was introduced.
This utility allows you to compile expressions and use them in the <Code>DataGrid</Code>.
The <Code>ExpressionCompiler</Code> can be used together with the <Code>DataGridColumnInfo</Code> collection provided by the <Code>ReadData</Code> in order to create Expression based queries (IQueryables) that can in turn be used in ORMs like Entity Framework.

Visit <Anchor To="/docs/extensions/datagrid/binding-data/large-data">DataGrid Binding Large Data</Anchor> for more information.
</Paragraph>

<NewsPageSubtitle>
Final Notes
</NewsPageSubtitle>
Expand Down

0 comments on commit a1407b3

Please sign in to comment.