Get filtered data from paged grid

1 Answer 6120 Views
Data Source
This question is locked. New answers and comments are not allowed.
Guru
Top achievements
Rank 2
Guru asked on 30 May 2012, 03:57 AM
What is a good way to get datasource results from a grid with paging and filtering applied and you want only the filtered out results?
I see many people asking this kind of question but not many real thorough answers.
datasource.data() gives you everything and datsource.view() gives you the current page you can see in the grid.

Do you have to calculate total / pagesize and iterate for each page...?
Iliana Dyankova
Telerik team
commented on 30 May 2012, 03:50 PM

Hello Zack,

I am not sure if I understand your question correctly, because the dataSource view() method returns a view of the result data from applied operation - such as paging and filtering.

Could you please provide more details about the scenario your are trying to implement?
 

Greetings,
Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Guru
Top achievements
Rank 2
commented on 30 May 2012, 04:44 PM

I have a grid with 3000 records in data source with a pageSize  of 5, that filtered shows 3 pages available and its count is 13 records.
If I do a datasource.view() I get 5 records (current page 1 of 3, i guess).
If I do a datasource.data() I get 3000 records.
I want to get 13 records (filtered results, ignoring paging).

1 Answer, 1 is accepted

Sort by
1
Accepted
Iliana Dyankova
Telerik team
answered on 31 May 2012, 11:50 AM
Hello Zack,

Such functionality is not supported out of the box, because the Kendo UI Grid widget displays the current view of the data. Hence when the grid paging is enabled and you filter the grid you are able to get only the data from  the current page, i.e. the current view.

In order to get all the filtered data when the grid is page-able you need to implement a custom logic for manipulation of the dataSource independently from the grid. The approach I would suggest is to get all the data and the applied filters from the dataSource. Then using a separate Query to get the whole filtered data. For example:
var dataSource = $("#grid").data("kendoGrid").dataSource;
var filters = dataSource.filter();
var allData = dataSource.data();
var query = new kendo.data.Query(allData);
var data = query.filter(filters).data;

I hope this helps.  
   
Regards,
Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Oskar
Top achievements
Rank 1
commented on 31 May 2012, 02:51 PM

Hi guys,

I was wandering about the same thing. What I did, was extending DataSource with my custom 'view' method. It switched off all on 'change' callbacks, set page size for 'total' number of items, got filtered data, set page size for old page size, then set old callbacks on.

But due to new changes in Kendo is not working anymore. It would be nice to have such function to obtain filtred/grouped/ordered data without paging.

Cheers,
Oskar.
Guru
Top achievements
Rank 2
commented on 31 May 2012, 04:38 PM

Yes, thank you Iliana that is perfect! I never tried the query method.
James Boman (IPMO)
Top achievements
Rank 1
commented on 17 Mar 2015, 12:33 AM

[quote]Iliana Nikolova said:
In order to get all the filtered data when the grid is page-able you need to implement a custom logic for manipulation of the dataSource independently from the grid. The approach I would suggest is to get all the data and the applied filters from the dataSource. Then using a separate Query to get the whole filtered data. For example:
var dataSource = $("#grid").data("kendoGrid").dataSource;
var filters = dataSource.filter();
var allData = dataSource.data();
var query = new kendo.data.Query(allData);
var data = query.filter(filters).data;
[/quote]

Iliana,
    Unfortunately this doesn't work and only ever provides the data from the first page - could you please provide a working example?

Here is what I am talking about:  http://dojo.telerik.com/@JBoman32768/EKUGe

Filter the results in the grid to yield more than one page of data, then press the button.  I only ever get the results for the first page :(

Cheers,
   James.
James Boman (IPMO)
Top achievements
Rank 1
commented on 17 Mar 2015, 02:47 AM

Never mind - I figured it out myself

http://dojo.telerik.com/@JBoman32768/Ucudi

Cheers,
   James.
Tags
Data Source
Asked by
Guru
Top achievements
Rank 2
Answers by
Iliana Dyankova
Telerik team
Share this question
or