I understand dataSource.view() returns only data from the current page and dataSource.data() is supposed to return everything. In our case, it does not for some reason.
Here's the DataSource setup from the server
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetRevenueData", "RevenueBudgetTool").Data("GetRevenueDataParams"))
.Model(mod => mod.Id(m => m.ClientId))
.PageSize(12)
)
And here's how we tried to get all the data in Javascript
$("#RevenueBudgetToolGrid").data("kendoGrid").dataSource.data();
The above line returns only 12 rows of data instead of 21 (total)
2 Answers, 1 is accepted
Indeed the view method returns the data items which correspond to the current page, but data returns the service response.
In the provided DataSource configuration a page size is specified, which means that a request will only take a portion of 12 items. If page size limitation is not configured the DataSource will request all the data and dataSource.data method will return all 21 items.
Regards,
Georgi
Progress Telerik
Hi!
I am trying to send all data from my grid to the server. I am doing as Fred did, but without the PageSize() in the DataSource(). However, I need to set the page size somehow as I have too much data, so I have it in Pageable() like this:
.Pageable(pageable => pageable
.PageSizes(
new
[] { 5, 10, 20 })
)
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action(
"GridRead_TimeTable"
,
"Dev"
))
)
But this in JavaScript
$(
"#grid"
).data(
"kendoGrid"
).dataSource.data();
still only returns the data from the current page.
How can I get all items while still having some sort of paging?
For a Kendo UI MVC Grid, you also need to specify ServerOperation(false) within the DataSource declaration.
When set as ServerOperation(true), the Grid DataSource data() method will return the same collection of dataItems as the view() method, which will be what is displayed on the current page and is constrained by the PageSize setting.
When set as ServerOperation(false), you can override the pagination and dataItems collection size.
Here's a sample code snippet for setting the ServerOperation attribute:
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)//set to false so can override the pagination and dataItems collection size
.AutoBind(true)//If set to false, the widget will not bind to the data source during initialization; the default value is true. Supported in ajax-bound mode.
...
)
Hi Chris's,
Even i got the same problem as view() and data() giving only current page records of grid. I can do the work around which you mentioned by changing the ServerOperation(true) to ServerOperation(false). But will it effect any of my grid paging and filteration.
Hello Pardhu,
When server operations are disabled, the grid will fetch the whole set of data with a single request and filter/group/page/sort/aggregate on the client. So for working with small amount of data it is okay to use client operations. However, if you working with large data sets, you will experience increase in initial loading time.
I hope this answers your question.
Regards,
Georgi
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Is there any way this can be achieved while we have pagination and serveroperation as true?
Hi, Sneha,
The data() method will always return all of the currently available data in the dataSource. If you have server paging enabled, the dataSource will contain data only for the current page. It simply does not have access to the rest of it.
I am not sure what the use-case scenario is, however if you need all of the data while keeping the server paging and pageSize the same, then you would have to make a separate request to the server to retrieve the entire set. You can either create a second standalone dataSource with no pageSize or you can make a manual $.ajax() request.
Best Regards,
Georgi