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

How to reorder multiple columns programitcally

3 Answers 1305 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Abhishek
Top achievements
Rank 1
Abhishek asked on 18 Sep 2014, 11:17 AM
Hi,

 We want to reorder columns on the grid based on some event. So lets say Grid has 3 columns A, B, and C. And on a button click, we want the new order to B, C, and A. Now we used the reorderColumn() method and called it 3 times for each column. But since each call expects indices, and columns are ordered on each reorderColumn() call, I am unable to have the desired column order. So I am unable to find a generic solution for this which will reorder columns according to my specifications.

 Can you please let me know how I can fix this.

Thanks a lot.

3 Answers, 1 is accepted

Sort by
1
Accepted
Dimiter Madjarov
Telerik team
answered on 19 Sep 2014, 08:38 AM
Hello Abhishek,


Here is a sample implementation which demonstrates how to achieve the current requirement.
E.g.
var newOrder = ["ShipName", "ShipCity", "ShipCountry"];
var grid = $("#grid").data("kendoGrid");
 
for (var i = 0; i < newOrder.length; i++) {
    var field = newOrder[i];
 
    $(grid.columns).each(function () {
        if (this.field === field) {
            grid.reorderColumn(i, this);
        }
    });
}

I have created an array which represents the names of the fields in the desired order. Then I am iterating over this array and the grid.columns object and reorder the columns.

I hope this information helps.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Abhishek
Top achievements
Rank 1
answered on 19 Sep 2014, 09:15 AM
Thanks a lot Dimiter for the quick response.
I was also thinking something similar, but this works like a charm.

Thanks a lot,
Abhishek
0
Dimiter Madjarov
Telerik team
answered on 19 Sep 2014, 10:08 AM
Hello Abhishek,


Thanks for the updated. I am glad the solution resolved the issue.

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