This is a migrated thread and some comments may be shown as answers.
Selecting rows on several pages
1 Answer 45 Views
This is a migrated thread and some comments may be shown as answers.
Gregory
Top achievements
Rank 1
Gregory asked on 11 Dec 2013, 04:35 PM
Hi, 

In one of my projects I have to display a Popup window with a grid (it is binded to a remote data source), allow the user to select
multiple rows from any of the grid's pages and copy them to another grid datasource when the user hit a button.

I have almost succeed in the way:
  •  I'm able to display both grid
  • I have added a checkbox to each row to allow users to select rows
  • store the Ids of my selected rows in a json string 
  • restore selection when user move from one page to another
  • Get the list of selected Ids
The problem I have now is that I'm able to copy to the target datasource only the data items of the current page.
Herebelow is the javascript function I use to copy data item:

function moveTo(from, to) {
     
    for (var i in checkedIds) {
         
        var isFound = to.dataSource.get(checkedIds[i]);
        if (checkedIds[i] != "") {
            if (isFound == undefined) {
                // Set 'From' Datasource to the correct page
                var ItemIdx = i % from.dataSource.pageSize();
                var PageNb = ((i - (ItemIdx)) / from.dataSource.pageSize()) + 1;
 
                //alert("Item: " + ItemIdx + " Page: " + PageNb);
                from.dataSource.page(PageNb);
                var view = from.dataSource.view();
 
                var item = view[ItemIdx];
                to.dataSource.add(item);
            }
        }
    }
}

When copying item from a not displayed page, the item from the current page, with the same index is copied instead
Note that the ItemIdx and PageNb are correct, this was double checked.

what am I doing wrong ?


1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 12 Dec 2013, 02:42 PM
Hi Gregory,

If I understand you correctly, you are trying to page the "from" dataSource to the correct page, where the desired data item is, then take the item and add it to the "to" dataSource. However, you are missing the fact that the page change executes an asynchronous remote request. In other words, the last three lines of code are executed too early.

Probably a more effective approach would be to obtain all desired data items with a single request via filtering.

http://docs.kendoui.com/api/framework/datasource#methods-filter

You will have to take into consideration the time needed to fetch all items, so the copying should occur in the "to" datasource's change event.

http://docs.kendoui.com/api/framework/datasource#events-change


Regards,
Dimo
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
Gregory
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or