Is it possible to copy a grid datasource to a new datasource, a new datasource that loads all data?

筅森魡賤 提交于 2020-02-02 12:29:06

问题


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.


回答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/




回答2:


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

http://jsfiddle.net/uj6sr9ez/42/




回答3:


Please try doing this:

var copyDataSource= kendo.data.DataSource.create({
    data: originalDataSource.data()
});


来源:https://stackoverflow.com/questions/26792861/is-it-possible-to-copy-a-grid-datasource-to-a-new-datasource-a-new-datasource-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!