Pagination not working with custom adapter

Pagination not working with custom adapter - the first page loads fine but subsequent pages generates NullReferenceException

Object reference not set to an instance of an object

-------------------------------------------------------------------------------------------

 public override Task<object> ReadAsync(DataManagerRequest dm, string key = null)

        {

            IEnumerable<SampleCtor> datasource = dbContext.SampleCtors.ToList();

            //IQueryable<SampleCtor> datasource = dbContext.SampleCtors;


            //var count = datasource.AsQueryable().Count();

            //datasource = DataOperations.Execute(datasource, dm);


            if (dm.Search != null && dm.Search.Count > 0)

            {

                // Searching

                datasource = DataOperations.PerformSearching(datasource, dm.Search);

            }

            if (dm.Sorted != null && dm.Sorted.Count > 0)

            {

                // Sorting

                datasource = DataOperations.PerformSorting(datasource, dm.Sorted);

            }

            if (dm.Where != null && dm.Where.Count > 0)

            {

                // Filtering

                datasource = DataOperations.PerformFiltering(datasource, dm.Where, dm.Where[0].Operator);

            }

            int count = datasource.Cast<SampleCtor>().Count();


            if (dm.Skip != 0)

            {

                //Paging

                //datasource = DataOperations.PerformSkip(datasource, dm.Skip);

                datasource = datasource.Skip(dm.Skip);

            }

            if (dm.Take != 0)

            {

                //datasource = DataOperations.PerformTake(datasource, dm.Take);

                datasource = datasource.Take(dm.Take);

            }



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


        }

 ---------------------------------------------------------------------------------------------

 System.NullReferenceException: Object reference not set to an instance of an object.

   at Syncfusion.Blazor.Grids.SfGrid`1.ModelChanged(ActionEventArgs`1 args, Object additionalArgs)

   at Syncfusion.Blazor.Grids.SfGrid`1.PagerClickHandler(PageChangedEventArgs args)

   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)

   at Syncfusion.Blazor.Grids.SfPager.NumericClickHandler(MouseEventArgs clickArgs, Double activePage)

   at Syncfusion.Blazor.Grids.SfPager.<>c__DisplayClass0_0.<<BuildRenderTree>b__13>d.MoveNext()

--- End of stack trace from previous location ---

   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)

   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)




1 Reply

SP Sarveswaran Palani Syncfusion Team June 20, 2022 04:44 PM UTC

Hi Frederick,


Thanks for contacting Syncfusion support


We had checked this scenario by creating a sample using CustomAdaptor as DataSource in our latest version(20.1.0.60). .But we are not able to reproduce the reported error at our end. We are attaching the sample in this ticket.


Kindly download and refer the sample in this ticket. If you are still facing the reported issue, then the following details would be helpful for us to proceed further.


  1. Share us the entire Grid code snippet
  2. Share the screenshot of the issue you are facing.
  3. Share the details of when you get an error
  4. If possible, reproduce the reported issue in the provided sample
  5. Or share issue reproducible sample


Above request details will be very helpful for us to further validate the reported query at our end and provide solution as easy as possible.


Regards,

Sarveswaran PK


Attachment: Pagination_99a17a03.zip

Loader.
Up arrow icon