Sort Grid Columns by "column_order" in JQWidgets

2k Views Asked by At

Is that possible to sort grid columns by column order dynamically using JQWidgets(v2.8.2)?

2

There are 2 best solutions below

0
On BEST ANSWER

Before generating the grid by

    `$(gridId).jqxGrid({
        source: dataAdapter,
        .............,
        ............,
        ............,
        columns:colData.columns  //column property from database
    });`

I sorted the the columns by columnOrder with sortColumnByOrder(colData.columns, 'columnOrder'); The original method is like below

function sortColumnByOrder(array, key) {
return array.sort(function(a, b) {
    var x = a[key];
    var y = b[key];
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}

And its working properly.

2
On

You can use the "sortby" method.

 $('#jqxgrid').jqxGrid('sortby', 'firstname', 'asc');

Example: http://jsfiddle.net/jqwidgets/7yWdu/. Hope it helps you.