Author Topic: Sorting By Displayed Text  (Read 1676 times)

MarquisMark9

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 4
    • View Profile
Sorting By Displayed Text
« on: February 28, 2017, 12:54:10 am »
We have a number of columns which use drop downs. The drop downs have display text which is a string and a value which is an int.  When the header is clicked to sort the column, it seems to be sorting by the int value, not the display text.  Is there a way to sort the column by its display text instead of the underlying value?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Sorting By Displayed Text
« Reply #1 on: February 28, 2017, 03:27:48 pm »
Default sorting can be replaced by custom sorting with help of column.sortType callback.

Assuming you save the displayed text values in the rowData with "prop" keynames.

Code: [Select]
        sortType: function( rowData1, rowData2 ) {

            var val1 = rowData1.prop || "",
                val2 = rowData2.prop || "";

            return val1.localeCompare(val2);
        },