diff --git a/Documentation/Blazorise.Docs/Models/Snippets.generated.cs b/Documentation/Blazorise.Docs/Models/Snippets.generated.cs index e01f417f66..5534ee3890 100644 --- a/Documentation/Blazorise.Docs/Models/Snippets.generated.cs +++ b/Documentation/Blazorise.Docs/Models/Snippets.generated.cs @@ -8761,9 +8761,9 @@ @using Blazorise.DataGrid.Utils Filterable FilterMode=""DataGridFilterMode.Menu""> - - - ((Gender)x).Code"" TextField=""(x) => ((Gender)x).Description"" /> + + + ( (Gender)x ).Code"" TextField=""( x ) => ( (Gender)x ).Description"" /> @@ -8782,28 +8782,27 @@ protected override async Task OnInitializedAsync() private int totalEmployees; - private async Task OnReadData(DataGridReadDataEventArgs e) + private async Task OnReadData( DataGridReadDataEventArgs e ) { - - if (!e.CancellationToken.IsCancellationRequested) + if ( !e.CancellationToken.IsCancellationRequested ) { - var query = employeeListSource.AsQueryable().ApplyDataGridSort(e.Columns).ApplyDataGridSearch(e.Columns); + 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)); + if ( dataGridRef.CustomFilter is not null ) + query = query.Where( item => item != null && dataGridRef.CustomFilter( item ) ); var response = new List(); - 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(); + if ( e.ReadDataMode is DataGridReadDataMode.Virtualize ) + response = query.ApplyDataGridVirtualization( e.VirtualizeOffset, e.VirtualizeCount ).ToList(); + else if ( e.ReadDataMode is DataGridReadDataMode.Paging ) + response = query.ApplyDataGridPaging( e.Page, e.PageSize ).ToList(); else - throw new Exception(""Unhandled ReadDataMode""); + throw new Exception( ""Unhandled ReadDataMode"" ); - await Task.Delay(Random.Shared.Next(100)); + await Task.Delay( Random.Shared.Next( 100 ) ); - if (!e.CancellationToken.IsCancellationRequested) + if ( !e.CancellationToken.IsCancellationRequested ) { totalEmployees = query.Count(); employeeList = response; diff --git a/Documentation/Blazorise.Docs/Pages/Docs/Extensions/DataGrid/Code/DataGridLargeDataExpressionCompilerExampleCode.html b/Documentation/Blazorise.Docs/Pages/Docs/Extensions/DataGrid/Code/DataGridLargeDataExpressionCompilerExampleCode.html index 4c3c554766..5f3f8dc3eb 100644 --- a/Documentation/Blazorise.Docs/Pages/Docs/Extensions/DataGrid/Code/DataGridLargeDataExpressionCompilerExampleCode.html +++ b/Documentation/Blazorise.Docs/Pages/Docs/Extensions/DataGrid/Code/DataGridLargeDataExpressionCompilerExampleCode.html @@ -14,9 +14,9 @@ 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" /> + <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> @@ -36,28 +36,27 @@ private int totalEmployees; - private async Task OnReadData(DataGridReadDataEventArgs<Employee> e) + private async Task OnReadData( DataGridReadDataEventArgs<Employee> e ) { - - if (!e.CancellationToken.IsCancellationRequested) + if ( !e.CancellationToken.IsCancellationRequested ) { - var query = employeeListSource.AsQueryable().ApplyDataGridSort(e.Columns).ApplyDataGridSearch(e.Columns); + 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)); + 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(); + if ( e.ReadDataMode is DataGridReadDataMode.Virtualize ) + response = query.ApplyDataGridVirtualization( e.VirtualizeOffset, e.VirtualizeCount ).ToList(); + else if ( e.ReadDataMode is DataGridReadDataMode.Paging ) + response = query.ApplyDataGridPaging( e.Page, e.PageSize ).ToList(); else - throw new Exception("Unhandled ReadDataMode"); + throw new Exception( "Unhandled ReadDataMode" ); - await Task.Delay(Random.Shared.Next(100)); + await Task.Delay( Random.Shared.Next( 100 ) ); - if (!e.CancellationToken.IsCancellationRequested) + if ( !e.CancellationToken.IsCancellationRequested ) { totalEmployees = query.Count(); employeeList = response; diff --git a/Documentation/Blazorise.Docs/Pages/Docs/Extensions/DataGrid/Examples/DataGridLargeDataExpressionCompilerExample.razor b/Documentation/Blazorise.Docs/Pages/Docs/Extensions/DataGrid/Examples/DataGridLargeDataExpressionCompilerExample.razor index f76a7c0ea0..f07a2c9ac4 100644 --- a/Documentation/Blazorise.Docs/Pages/Docs/Extensions/DataGrid/Examples/DataGridLargeDataExpressionCompilerExample.razor +++ b/Documentation/Blazorise.Docs/Pages/Docs/Extensions/DataGrid/Examples/DataGridLargeDataExpressionCompilerExample.razor @@ -13,9 +13,9 @@ Filterable FilterMode="DataGridFilterMode.Menu"> - - - + + + @@ -34,28 +34,27 @@ private int totalEmployees; - private async Task OnReadData(DataGridReadDataEventArgs e) + private async Task OnReadData( DataGridReadDataEventArgs e ) { - - if (!e.CancellationToken.IsCancellationRequested) + if ( !e.CancellationToken.IsCancellationRequested ) { - var query = employeeListSource.AsQueryable().ApplyDataGridSort(e.Columns).ApplyDataGridSearch(e.Columns); + 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)); + if ( dataGridRef.CustomFilter is not null ) + query = query.Where( item => item != null && dataGridRef.CustomFilter( item ) ); var response = new List(); - 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(); + if ( e.ReadDataMode is DataGridReadDataMode.Virtualize ) + response = query.ApplyDataGridVirtualization( e.VirtualizeOffset, e.VirtualizeCount ).ToList(); + else if ( e.ReadDataMode is DataGridReadDataMode.Paging ) + response = query.ApplyDataGridPaging( e.Page, e.PageSize ).ToList(); else - throw new Exception("Unhandled ReadDataMode"); + throw new Exception( "Unhandled ReadDataMode" ); - await Task.Delay(Random.Shared.Next(100)); + await Task.Delay( Random.Shared.Next( 100 ) ); - if (!e.CancellationToken.IsCancellationRequested) + if ( !e.CancellationToken.IsCancellationRequested ) { totalEmployees = query.Count(); employeeList = response; diff --git a/Source/Extensions/Blazorise.DataGrid/Utils/ExpressionCompiler.cs b/Source/Extensions/Blazorise.DataGrid/Utils/ExpressionCompiler.cs index b452bc321b..cb6c3f5094 100644 --- a/Source/Extensions/Blazorise.DataGrid/Utils/ExpressionCompiler.cs +++ b/Source/Extensions/Blazorise.DataGrid/Utils/ExpressionCompiler.cs @@ -308,13 +308,14 @@ public static IQueryable ApplyDataGridSort( this IQueryable } /// - /// Applies the paging filter to the queryable data. + /// Applies paging to the specified based on the provided page number and page size. /// - /// - /// The Data to be queried - /// The current page - /// The page size - /// + /// The type of the elements in the queryable data source. + /// The queryable data source to which paging will be applied. + /// The page number to retrieve. Must be greater than 0. + /// The number of items per page. Must be greater than 0. + /// A new containing the items for the specified page, or the original data source if + /// or is less than or equal to 0. public static IQueryable ApplyDataGridPaging( this IQueryable data, int page, int pageSize ) { if ( page > 0 && pageSize > 0 ) @@ -325,6 +326,26 @@ public static IQueryable ApplyDataGridPaging( this IQueryable + /// Applies virtualization to the specified queryable data source by skipping a specified number of items and + /// taking a specified number of items. + /// + /// The type of the elements in the data source. + /// The queryable data source to apply virtualization to. + /// The number of items to skip. Must be greater than or equal to 0. + /// The number of items to take. Must be greater than 0. + /// A queryable data source containing the specified range of items. If is less than 0 or + /// is less than or equal to 0, the original data source is returned. + public static IQueryable ApplyDataGridVirtualization( this IQueryable data, int offset, int count ) + { + if ( offset >= 0 && count > 0 ) + { + return data.Skip( offset ).Take( count ); + } + + return data; + } + /// /// Applies all the DataGrid filters to the queryable data. ///