diff --git a/Demos/Blazorise.Demo/Pages/Tests/DataGrid/DataGridPage.razor.cs b/Demos/Blazorise.Demo/Pages/Tests/DataGrid/DataGridPage.razor.cs index f760e9638a..bbf7ca3b5c 100644 --- a/Demos/Blazorise.Demo/Pages/Tests/DataGrid/DataGridPage.razor.cs +++ b/Demos/Blazorise.Demo/Pages/Tests/DataGrid/DataGridPage.razor.cs @@ -206,21 +206,13 @@ private async Task OnReadData( DataGridReadDataEventArgs e ) if ( !e.CancellationToken.IsCancellationRequested ) { - var query = dataModels.AsQueryable().ApplyDataGridSort( e.Columns ).ApplyDataGridSearch( e.Columns ); + var query = dataModels.AsQueryable().ApplyDataGridSort( e ).ApplyDataGridSearch( e ); if ( dataGrid.CustomFilter is not null ) query = query.Where( item => item != null && dataGrid.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(); - else - throw new Exception( "Unhandled ReadDataMode" ); + response = query.ApplyDataGridPaging( e ).ToList(); await Task.Delay( random.Next( 100 ) ); diff --git a/Source/Extensions/Blazorise.DataGrid/Utils/ExpressionCompiler.cs b/Source/Extensions/Blazorise.DataGrid/Utils/ExpressionCompiler.cs index 57c8c2a4ec..4c9ad573b8 100644 --- a/Source/Extensions/Blazorise.DataGrid/Utils/ExpressionCompiler.cs +++ b/Source/Extensions/Blazorise.DataGrid/Utils/ExpressionCompiler.cs @@ -27,8 +27,8 @@ public static IQueryable ApplyDataGridFilters( this IQueryable /// - /// - /// + /// The Data to be queried + /// The DataGrid Columns Info /// public static IQueryable ApplyDataGridSearch( this IQueryable data, IEnumerable dataGridColumns ) { @@ -269,8 +269,8 @@ public static IQueryable ApplyDataGridSearch( this IQueryable /// - /// - /// + /// The Data to be queried + /// The DataGrid Columns Info /// public static IQueryable ApplyDataGridSort( this IQueryable data, IEnumerable dataGridColumns ) { @@ -311,9 +311,9 @@ public static IQueryable ApplyDataGridSort( this IQueryable /// Applies the paging filter to the queryable data. /// /// - /// - /// - /// + /// The Data to be queried + /// The current page + /// The page size /// public static IQueryable ApplyDataGridPaging( this IQueryable data, int page, int pageSize ) { @@ -325,6 +325,59 @@ public static IQueryable ApplyDataGridPaging( this IQueryable + /// Applies all the DataGrid filters to the queryable data. + /// + /// The TItem + /// The Data to be queried + /// The DataGrid Read Data Event Arguments + /// + public static IQueryable ApplyDataGridFilters( this IQueryable data, DataGridReadDataEventArgs dataGridReadDataEventArgs ) + { + return data.ApplyDataGridSort( dataGridReadDataEventArgs ).ApplyDataGridSearch( dataGridReadDataEventArgs ).ApplyDataGridPaging( dataGridReadDataEventArgs ); + } + + /// + /// Applies the search filter to the queryable data. + /// + /// + /// The Data to be queried + /// The DataGrid Read Data Event Arguments + /// + public static IQueryable ApplyDataGridSearch( this IQueryable data, DataGridReadDataEventArgs dataGridReadDataEventArgs ) + { + return data.ApplyDataGridSearch( dataGridReadDataEventArgs.Columns ); + } + + /// + /// Applies the sort filter to the queryable data. + /// + /// + /// The Data to be queried + /// The DataGrid Read Data Event Arguments + /// + public static IQueryable ApplyDataGridSort( this IQueryable data, DataGridReadDataEventArgs dataGridReadDataEventArgs ) + { + return data.ApplyDataGridSort( dataGridReadDataEventArgs.Columns ); + } + + /// + /// Applies the paging filter to the queryable data. + /// + /// + /// The Data to be queried + /// The DataGrid Read Data Event Arguments + /// + public static IQueryable ApplyDataGridPaging( this IQueryable data, DataGridReadDataEventArgs dataGridReadDataEventArgs ) + { + if ( dataGridReadDataEventArgs.ReadDataMode is DataGridReadDataMode.Virtualize ) + data = data.ApplyDataGridPaging( dataGridReadDataEventArgs.VirtualizeOffset + 1, dataGridReadDataEventArgs.VirtualizeCount ); + else if ( dataGridReadDataEventArgs.ReadDataMode is DataGridReadDataMode.Paging ) + data = data.ApplyDataGridPaging( dataGridReadDataEventArgs.Page, dataGridReadDataEventArgs.PageSize ); + + return data; + } + /// /// Creates the lambda expression that is suitable for usage with Blazor . ///