This is a migrated thread and some comments may be shown as answers.

Ajax() datasource, but want all data in one request

2 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 2
Iron
Iron
Veteran
Jay asked on 02 Jun 2015, 07:38 PM

So, I've got a grid configured as such

.DataSource(dataSource => dataSource
     .Ajax()
     .ServerOperation(false)
     .PageSize(250)
     .Read(read => read.Action("_readData", "Data", new { Id= Model.Id })))
.Scrollable(scrolling => scrolling.Enabled(true))
.Sortable()
.Pageable(paging => paging.Enabled(true)
                 .PageSizes(false)
                 .Input(false)
                 .Info(true)
                 .Numeric(false)
                 .PreviousNext(false)
                 .Messages(m => m.Display("Total Records: {2}")))

In the _readData() method of my controller, all data is retrieved and returned and the Total Records displayed reflects that.

var data = ReadData();
DataSourceResult result = data.ToDataSourceResult(request);
return Json(result);

However, the grid itself only displays 250 (the PageSize) items, even though all the items were returned, and nothing else gets displayed.

If I set Virtual(true) on the scrollable, then the grid will call out to the server again as I scroll, and once again all items data is retrieved, but it seems to only make use of the returned items PageSize at a time -- each time I scroll more than that, it calls back to the server to once again get all items, etc.

I thought ServerOperation(false) would tell the grid that all data will be requested through a single request so it wouldn't have to call back to the server each time.

The only thing I've found to work is to set PageSize(100000) (with or without virtual scrolling and with or without ServerOperation doesn't seem to affect it) to ensure that the number of items displayed is all the data that was returned, which in this case is only about 3000. This works, but seems pretty hacky.

Is there a better way to accomplish what I want?

2 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 05 Jun 2015, 11:39 AM

Hello Jay,

Indeed, setting the ServerOperation to false should request all of the data and apply the operations such as paging, sorting, grouping and filtering in-memory. Thus, with the configuration in question, the DataSource should get all of the available data and the Grid widget should show the first page (the first 250 records). Than when paged it should display the next page, if there is such, without hitting the server. From the provided description and if I have understood correctly, you are not getting this behavior. Is this correct?

However, in case you just want to display all of the available records you will need to remove the DataSource pageSize option and disable the paging by removing the Pageable option from the Grid.

Regards,
Rosen
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jay
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 05 Jun 2015, 12:37 PM

Hi Rosen. Thanks, that's what I needed! Removing the pageSize and Pageable settings, together with including ServerOperation(false), gave me the behavior I wanted, that is, all items are returned in one request and sorting etc does not hit the server again. Thanks again!

Tags
Grid
Asked by
Jay
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Rosen
Telerik team
Jay
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or