jQuery UI Widgets › Forums › General Discussions › Custom sort function
This topic contains 3 replies, has 3 voices, and was last updated by samanthakjohnson 1 year, 4 months ago.
-
AuthorCustom sort function Posts
-
Hi,
In a jqxGrid, is it possible to have a custom sort function on a column ?
Something like that :$("#jqxGrid").jqxGrid( { columns: [ {... {text: 'label', datafield: 'label', sortmode: function (val1, val2) { if (some non standard sort condition on val1 and val2) return true else return false; } } ]}
Best regards
- This topic was modified 1 year, 10 months ago by antonomase.
Hi antonomase,
Yes, this functionality is achievable with jqxGrid component and we have documentation and demos for it.
Link to the documentation: https://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxgrid/jquery-grid-sorting.htm
Link to the demo: https://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/customsorting.htm?ui-startLet me know what you think!
Please, do not hesitate to contact us if you have any additional questions.
Best Regards,
Yavor Dashev
jQWidgets team
https://www.jqwidgets.comHi Yavor,
Thanks for the answer
I added some lines to answer my need : sort dates in dd/mm/yyyy format but in a textBox field and not a dateTimeInput field
$(document).ready(function () { // prepare the data var data = generatedata(20); var sortcolumn; var customsortfunc = function (column, direction) { var sortdata = new Array(); //Store the current sort column sortcolumn = column; ... var compare = function (value1, value2) { if (sortcolumn === 'textDate') { //Reverse dd/mm/yyyy to yyyymmdd tmpvalue1 = String(value1).substr(-4)+String(value1).substr(3,2)+String(value1).substr(0,2); tmpvalue2 = String(value2).substr(-4)+String(value2).substr(3,2)+String(value2).substr(0,2); value1 = tmpvalue1; value2 = tmpvalue2; } ...
This meets the need, but it is not very elegant. A callback function associated to the sorting on the column would be more consistent with the other behaviors on this column (renderer, filter,…).
- This reply was modified 1 year, 10 months ago by antonomase.
nice post
-
AuthorPosts
You must be logged in to reply to this topic.