Is that possible to sort grid columns by column order
dynamically using JQWidgets(v2.8.2)
?
Asked
Active
Viewed 2,046 times
0

Amit
- 15,217
- 8
- 46
- 68

silk_route11
- 324
- 3
- 17
-
Please elaborate & provide your current code. As it currently stands, this would not be considered a quality question. – Dom Jan 07 '14 at 06:54
-
I am generating a grid by `$(gridId).jqxGrid({source: dataAdapter,......,columns: colData.columns});`The default column properties come from database, which is initialized from a json file.Now, on "personalize grid" option of this grid, I should be able to change the order of columns(which is done). But the new column order doesn't take effect after refreshing it by `$(gridId).jqxGrid('refresh');` – silk_route11 Jan 07 '14 at 07:12
2 Answers
0
You can use the "sortby" method.
$('#jqxgrid').jqxGrid('sortby', 'firstname', 'asc');
Example: http://jsfiddle.net/jqwidgets/7yWdu/. Hope it helps you.

scripto
- 2,297
- 1
- 14
- 13
-
I think there is difference between `column property` and `column value(cell value)`. The `column order` is a column property. `$('#jqxgrid').jqxGrid('sortby', 'firstname', 'asc');` This is for row sorting by `'firstname'` column values within this column i guess. – silk_route11 Jan 07 '14 at 08:32
-
0
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.

silk_route11
- 324
- 3
- 17