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

Accessing updated columns collection in columnReorder event

2 Answers 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sherman
Top achievements
Rank 1
Sherman asked on 13 Jan 2015, 05:23 PM
columnReorder: function (e) {
    var grid = e.sender;
    for (var i = 0; i < grid.columns.length; i++) {
        console.log(grid.columns[i].field);
    }
}

This is returning the columns collection's ordering before the reorder occurs.  How do I access the new columns collection during the columnReorder event?

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 15 Jan 2015, 01:07 PM
Hello,

Indeed, the event is triggered before the columns are actually reordered so the columns array will be the old one. You could either use a timeout to wait for the columns to be reordered:
columnReorder: function (e) {
    setTimeout(function () {
        var columns = e.sender.columns;
    }, 0);       
}

or the newIndex and oldIndex parameters to get the columns in the updated order.
var columns = e.sender.columns.slice(0);
var column = columns.splice(e.oldIndex, 1)[0];
columns.splice(e.newIndex, 0, column);


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Steve
Top achievements
Rank 1
answered on 20 Aug 2015, 06:20 PM
This timeout works great! This trick should be in the main Telerik grid documentation.
Tags
Grid
Asked by
Sherman
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Steve
Top achievements
Rank 1
Share this question
or