Grid Pagination - Dynamic number of records/page count

Hi,

How do I change the total number of pages displayed at the bottom of the grid when only loading the current page?

If I have a dynamic data source, which users can filter outside of the grid the page count will change depending on the results of the search. Also as mentioned, we only take the results one page at a time.


For example, my page size is set to 20. I search for X, Y and Z which would result in a total of 100 records but I only return the first 20 of those as I am only loading the first page. I would expect 5 pages to be displayed along the bottom. If I now search only for X and Y, I only get back 60 records (only taking the first 20 again) but I would expect 3 pages to be displayed along the bottom.


I have the paging sorted and the total number of records, how do I update the total number of records on SfGrid? It calculates the PageCount based on the data source, setting GridPageSettings.PageCount doesn't refresh when the data source changes and doesn't even seem to do anything when I have it set explicitly.


Thanks in advance, Lee.


3 Replies

MS Monisha Saravanan Syncfusion Team July 14, 2023 12:52 PM UTC


Hi Lee,


Greetings from Syncfusion.


We suspect that you are loading only the particular subset of data the data to the Grid. If so the Grid page settings will be calculated based on the number of records you fetch from the server.


i.e.) For example: If we have 100 records and if you are fetching only the first 20 records then the DataSource count will be assigned  as 20 and it will render only one page. So instead of fetching a subset of records, we recommend passing the entire data source to the grid at the initial rendering. Once the data is loaded, you can utilize the custom adaptor feature of the DataGrid. By implementing a custom adaptor, you can perform skip and take operations to retrieve the desired result based on your paging requirements.


Reference: https://blazor.syncfusion.com/documentation/data/custom-binding

https://blazor.syncfusion.com/documentation/datagrid/data-binding#sql-server-data-bindingsql-client


If we misunderstood your query then kindly share us the simple issue reproduceable sample or video demonstration of the reported issue.


Regards,

Monisha



LS Lee Stevens July 24, 2023 12:22 PM UTC

Hi Monisha,

You're correct in that I only want to load a subset, I do not want to get the full data source. This isn't practical if there are thousands of records.

I can provide the count of records but only want to load the records for a single page at a time. 

If I am loading the full data source, what is the point of paging in the first place? 


Look forward to hearing from you.



MS Monisha Saravanan Syncfusion Team July 25, 2023 09:45 AM UTC

Hi Lee,


Query: “I can provide the count of records but only want to load the records for a single page at a time. ”


If you can provide the count in prior then we suggest you to try the custom adaptor feature at your end. By using custom adaptor we can pass the total count using count property. So that it will display pages based on the count. Kindly check the below highlighted codes and documentation for your reference. Also please refer the attached sample for additional information.


Reference: https://blazor.syncfusion.com/documentation/data/custom-binding


 

<SfGrid TValue="Order" ID="Grid" AllowSorting="true" AllowFiltering="true" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })">

    <SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>

    <GridPageSettings PageSize="15" PageCount="3"></GridPageSettings>

    <GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>

    <GridColumns>

...

    </GridColumns>

</SfGrid>

 

@code {

    public static List<Order> Orders { get; set; }

 

    public class CustomAdaptor : DataAdaptor

    {

        // Performs data Read operation

        public override object Read(DataManagerRequest dm, string key = null)

        {

            IEnumerable<Order> DataSource = Orders;

            // instaed of getting the conts from datasource property use the static datasource count.

            //int count = DataSource.Cast<Order>().Count();

            int count = 40;

            return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;

        }

 

         }

}


If you face still face any difficulties then kindly share us the below details to validate further at our end.


  1. Share us the entire Grid code snippet.
  2. Share us the video demonstration of the issue.
  3. If possible kindly share us an simple issue reproduceable sample.


The above requested details will be very helpful for us to validate the reported issue at our end.





Attachment: BlazorApp1_573c8f56.zip

Loader.
Up arrow icon