This is a migrated thread and some comments may be shown as answers.

Clone datasource between datagrids

1 Answer 408 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Irene
Top achievements
Rank 2
Irene asked on 14 Sep 2015, 09:55 AM

Hi,

We have a window with 2 datagrids that allow select data from one grid to another. We have the four tipical options (add one, remove one, add all, remove all), our problem is in the "add all" option.

 We need to clone the datasource from one grid to another and this is our try:

 

var gridAllData = $("gridAll").data("kendoGrid");
var gridSelectedData = $("gridSel").data("kendoGrid");
 
var ds = new kendo.data.DataSource();
gridSelectedData.setDataSource(ds);
 
var allData = gridAllData.dataSource.data();
var filters = gridAllData.dataSource.filter();
var query = new kendo.data.Query(allData);
var dataFilter = query.filter(filters).data;
for (var i=0; i < dataFilter.length; i++){
  ds.add(dataFilter[i]);
}
 
gridSelectedData.pager.page(1);
gridSelectedData.dataSource.pageSize(10);

 

The problem is that it's very slow when there are many records. What is the best method to clone the datasource?

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 16 Sep 2015, 07:25 AM
Hello Irene,

The slowest operation should be the for loop where add method is called.
Please try to replace the whole data at once through the data method of the dataSource instead of calling add multiple times.

Also it will help if you set the dataSource to the Grid after the dataSource is populated.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Irene
Top achievements
Rank 2
Answers by
Alexander Valchev
Telerik team
Share this question
or