dataSource.data() does not return all data

2 Answers 3771 Views
Grid
Fred
Top achievements
Rank 1
Fred asked on 31 Jul 2017, 08:45 PM

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

Sort by
0
Accepted
Georgi
Telerik team
answered on 03 Aug 2017, 05:23 AM
Hi Fred,

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Andreas
Top achievements
Rank 1
commented on 27 Jun 2019, 11:03 AM

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?

Chris
Top achievements
Rank 1
Iron
commented on 27 Jun 2019, 06:41 PM

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.
    ...
)

Andreas
Top achievements
Rank 1
commented on 28 Jun 2019, 06:59 AM

Wonderful, thank you!
pardhu
Top achievements
Rank 1
commented on 12 Jun 2020, 04:06 PM

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.

 

pardhu
Top achievements
Rank 1
commented on 12 Jun 2020, 04:10 PM

will it work for Kendo Jquery grid also?
0
Georgi
Telerik team
answered on 16 Jun 2020, 12:34 PM

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Sneha
Top achievements
Rank 1
Iron
commented on 22 Aug 2023, 12:23 PM

Is there any way this can be achieved while we have pagination and serveroperation as true?

 

Georgi Denchev
Telerik team
commented on 24 Aug 2023, 07:33 AM

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

Tags
Grid
Asked by
Fred
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or