Is it possible to copy a grid datasource to a new datasource, a new datasource that loads all data? For example I have a kendo grid which has a page size of 10, how would I copy it into a new datasource which will load all the data and ignore the paging.
Asked
Active
Viewed 6,691 times
2
-
But should it go to the server for getting the data? If so, just copy the DataSource definition and overwrite the paging value. – OnaBai Nov 07 '14 at 05:32
-
i tried querying the datasource setting the paging value to 0 but the data returned to the view was only the number of the current paging. – ECie Nov 07 '14 at 05:50
-
You should set `serverPaging` to false (check documentation here: http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-serverPaging) – OnaBai Nov 07 '14 at 06:56
-
that's what i think i am missing... gonna try sir – ECie Nov 07 '14 at 08:10
3 Answers
1
Some aspects might depend on how did you define the DataSource of the first (pageable) datasource. But basically you need to copy the original data source, then change the value for pageSize
and serverPaging
and finally assign it to the second grid using setDataSource
.
Example:
// First DataSource definition
var ds1 = {
transport: {
read: ...
},
pageSize: 10,
schema : {
model: {
...
}
}
};
// Copy ds1 definition into ds2
var ds2 = ds1;
// Change values for serverPaging and pageSize
ds2.serverPaging = false;
ds2.pageSize = 0;
// Create new DataSource object and assign it to the second Grid
grid2.setDataSource(new kendo.data.DataSource(ds2));
You can see this running in the following JSFiddle : http://jsfiddle.net/OnaBai/uj6sr9ez/

OnaBai
- 40,767
- 6
- 96
- 125
-
thanks... this is what i've been looking for. not documented by kendo.. thaks sir onabai – ECie Nov 10 '14 at 05:20
-
@EduCielo Could you elaborate your exact question? I cannot see why it has to be a problem loading it from a server. Maybe post a separate question with your problem – OnaBai Jul 22 '15 at 11:53
-
5Am I missing something here or does this example merely create a new reference to the same DataSource? "var ds2 = ds1;" assigns the address of the DataSource for which ds1 is a reference. If you change it thru ds2 you're changing the same (one and only) DataSource as ds1 points to. You'd need to do some sort of deep clone to get a second DataSource from the first. – Will Sep 27 '16 at 17:18
0
From @Will comment, I think a better solution is:
// First DataSource definition
var ds1 = {
// ...
// Create the new kendo datasource, so ds1 is not modified
var ds2 = new kendo.data.DataSource(ds1);
ds2.pageSize(-1);
ds2.serverPaging = false;
grid2.setDataSource(ds2);

thepirat000
- 12,362
- 4
- 46
- 72
0
Please try doing this:
var copyDataSource= kendo.data.DataSource.create({
data: originalDataSource.data()
});

Dmitry Kuzminov
- 6,180
- 6
- 18
- 40

Varun
- 1