Hi,
I have a large dataset displayed in a SfGrid, which refreshes periodically. The requirement is to sort the grid with a descending/ascending sorting on a column, say 'SalesQuantity'. And I want the grid to display ONLY the top 10 rows.
You might propose: from your database, only bring the top 10 rows. This works for sure. But the sortable columns are multiple, say 20. This will lead to code 20 different DB queries to bring me the suitable data. This lead me to ask question here, is it possible to achieve this with the graphic component?
Thanks,
Yi
Hi Yi Han,
Greetings from Syncfusion.
We suspect that you want to get only the top 10 records from your database after sorting with multiple columns initially. You can achieve your requirement by using CustomAdaptor as a component or initial sorting. While using the CustomAdaptor way, you can send the SQL query(containing sorting and getting top records) to your database with a single request for fetching data and display it to the Grid.
Find the below documentation for your reference.
Reference:
https://blazor.syncfusion.com/documentation/datagrid/data-binding#sql-server-data-bindingsql-client
(Or)
You can try to define the Initial sorting operation to achieve this case from your end.
Reference:
https://blazor.syncfusion.com/documentation/datagrid/sorting#initial-sort
If it does not meet your requirement, then please more details about your requirement.
Please let us know if you have any concerns.
Regards,
Rahul
Hi Rahul,
Thank you for your reply.
Unfortunately both options that you suggested do not meet my requirement. My requirement is:
1/ I don't know on which column the sorting will be applied in advance
2/ The `DataSource` of the grid is a cache (not from a DB query) containing > 2000 lines - this DataSource is also used for other use cases.
3/ when the sorting is applied on one column, I wan't to display only 10 items in the grid, accordingly to the sorting when user click on the sorting column.
Say it in another way, it's just like a grid with paging with a page size of 10. But the grid displays ONLY the first page.
Hope this clarifies my requirement.
Please suggest, Many thanks.
Yi
Hi Yi Han,
Thanks for the update.
We are quite unclear about your requirement case. So we need some details regarding your reported query. Could you please share the below details which will be helpful to validate and provide a better solution?
Regards,
Rahul
Hi,
Thank you for your reply.
I attached a sample project for your analysis.
Please suggest, many thanks
Yi
Hi Yi Han,
Thanks for the update.
Based on your case, we suggest you to use the paging(AllowPaging) feature to achieve your requirement. Set AllowPaging as true and set PageSize property as 10 in GridPageSettings. Find the below code snippets and sample for your reference.
|
<SfGrid DataSource="@Orders" AllowPaging="true" AllowSorting="true" Height="270"> <GridPageSettings PageSize="10"></GridPageSettings> <GridColumns> . . . </GridColumns> </SfGrid> |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorSample-1493452507
Reference:
https://blazor.syncfusion.com/documentation/datagrid/getting-started#enable-paging
https://blazor.syncfusion.com/documentation/datagrid/paging
Please let us know if you have any concerns.
Regards,
Rahul
Hi Rahul,
Thank you for your reply.
That's the work around that I found on my side.
My expectation, really, is don't show all the pages:
Possible to achieve?
Thanks
Yi
Hi Yi Han,
Thanks for the update.
We suspect that you want to render only 10 records in the Grid without using the Paging feature. We suggest you to achieve your requirement by using the Query property of the Grid. Find the below code snippets and sample for your reference.
|
@using Syncfusion.Blazor @using Syncfusion.Blazor.Data
<SfGrid DataSource="@Orders" AllowSorting="true" Height="270" Query=@GridQuery> <GridColumns> <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" AutoFit="true"></GridColumn> <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" AutoFit="true"></GridColumn> <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" AutoFit="true"></GridColumn> <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" AutoFit="true"></GridColumn> </GridColumns> </SfGrid>
@code{ public ObservableCollection<Order> Orders { get; set; }
public Query GridQuery { get; set; } = new Query().Take(10);
. .. } |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SampleGrid368294559
Please let us know if you have any concerns.
Regards,
Rahul