Author Topic: custom sorting ignored  (Read 2825 times)

[email protected]

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 30
    • View Profile
custom sorting ignored
« on: February 18, 2015, 01:00:09 am »
Hello,

I have the following custom dataType in order to provide custom sorting on date fields using special date format:

var pqcolmodel=[
      {dataIndx: 'col1', title: ' ', width: '5px', align: 'center', copy: true, minWidth: 30},
      {dataIndx: 'col2', title: 'issued', width: '80px', align: 'right', dataType: function (val1, val2) {return compareDate(val1, val2);}, copy: true, minWidth: 30}
    ];

function compareDate() returns -1, 0, 1 depending on val1 and val2.

this is datamodel:
var pqdatamodel={
  location: 'local',
  data: pqdata1,
  sorting: 'local',
  sortIndx: ['col13'],
  sortDir: ['down']
}

But it seems the custom sorting is never called.
Even this code returns "undefined".

    //getter
    var colM = $( "#grid_md" ).pqGrid( "option", "colModel" );
    var dataType = colM[1].dataType;
    console.debug(dataType);

What do I do wrong?

Thanks,

Jan

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: custom sorting ignored
« Reply #1 on: February 18, 2015, 11:48:51 am »
sortIndx looks incorrect in your code. Also check whether you have passed pqcolmodel to the grid correctly. Please post a jsfiddle if still facing issues.

You can also use column.sortType ( introduced in v2.4.0 ) to implement custom sorting.
http://paramquery.com/pro/demos/sorting_custom

http://paramquery.com/pro/api#option-column-sortType

[email protected]

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 30
    • View Profile
Solved: custom sorting ignored
« Reply #2 on: February 22, 2015, 03:10:14 pm »
Thanks for a help, the reason was in the fact I save colModel in localstorage and load it again. JSON.stringify ommit dataType functions during stringify... I reset custom dataType again after load an it works again.