jQuery UI Widgets › Forums › Grid › Sort custom
Tagged: angular grid, custom sorting, grid, jquery grid, jqxgrid, sort, sortby, sorting
This topic contains 3 replies, has 2 voices, and was last updated by Dimitar 8 years, 10 months ago.
-
AuthorSort custom Posts
-
Hello everyone,
I have to order my jqGrid especially, exactly this way
3 – P
8 – D
8 – C
6 – A
in particular:
P
P
P
D
D
D
D
D
D
D
D
C
C
C
C
C
C
C
C
A
A
A
A
A
AHow can I do? Help me please.
Thank you all.Hello amatost,
jqxGrid allows for the implementation of custom sorting, as shown in the following demo: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/customsorting.htm?arctic.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thanks, Dimitar
but unfortunately I am not an experienced programmer, I have to implement this code?:
var customsortfunc = function (column, direction) { var sortdata = new Array(); if (direction == 'ascending') direction = true; if (direction == 'descending') direction = false; if (direction != null) { for (i = 0; i < data.length; i++) { sortdata.push(data[i]); } } else sortdata = data; var tmpToString = Object.prototype.toString; Object.prototype.toString = (typeof column == "function") ? column : function () { return this[column] }; if (direction != null) { sortdata.sort(compare); if (!direction) { sortdata.reverse(); } } source.localdata = sortdata; $("#jqxgrid").jqxGrid('updatebounddata', 'sort'); Object.prototype.toString = tmpToString; } // custom comparer. var compare = function (value1, value2) { value1 = String(value1).toLowerCase(); value2 = String(value2).toLowerCase(); try { var tmpvalue1 = parseFloat(value1); if (isNaN(tmpvalue1)) { if (value1 < value2) { return -1; } if (value1 > value2) { return 1; } } else { var tmpvalue2 = parseFloat(value2); if (tmpvalue1 < tmpvalue2) { return -1; } if (tmpvalue1 > tmpvalue2) { return 1; } } } catch (error) { var er = error; } return 0; };
could you kindly give me an example related to my case?
Best regards,
AmatoHi Amato,
I just now realise that you would like to sort alphabetically, but descending. If so, you do not really need to implement custom sorting. Just call the method sortby and pass ‘desc’ as second parameter. Here is an example with this method: http://jsfiddle.net/jqwidgets/7yWdu/. If you wish your grid to be sorted by default, call sortby in the ready callback function.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.