Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by briank on Aug 03, 2009 10:04
open dhtmlx forum
XML Configure Not Sorting

Having a problem sorting columns when using XML to configure the header. getSortingState() always returns undefined values when configuring columns in the xml head element. Updated the grid_config_xml.html example located in the "initialization_loading" directory with a slight modification and ended up with the same results.

Unedited Version:
mygrid = new dhtmlXGridObject('gridbox');
mygrid.setImagePath("../../codebase/imgs/");
mygrid.loadXML("gridH.xml");


Edited Version:
mygrid = new dhtmlXGridObject('gridbox');
mygrid.setImagePath("../../codebase/imgs/");
mygrid.attachEvent("onBeforeSorting",onBeforeSorting);
mygrid.loadXML("gridH.xml");

function onBeforeSorting(){
var a_state = mygrid.getSortingState();
alert(a_state[1]);
}

Is there a command needed to properly sort server side data when configuring the column names through XML?
Answer posted by dhxSupport on Aug 04, 2009 03:13
After grid was loaded getSortingState() allways return empty array as no one column was sorted yet. 
If you change onBeforeSorting() function like following, alert will return correct value only after second "onBeforeSorting" event occurrence
function onBeforeSorting(ind,type,direction){ 
  var a_state = mygrid.getSortingState(); 
  alert(a_state[1]); 
  return true;
 }
"onBeforeSorting" event occurs before starting data sorting but not finished yet. This event is blockable (if custom code, attached to event, returns value different from true - sorting operation will be blocked). Also to define sorting dicrection you can use event's handler parameters:
ind - column index
type - sorting type (“str”,”int”,”date”)
direction - direction of sorting (“asc”,”des”)


Answer posted by briank on Aug 04, 2009 05:59
Thanks. onBeforeSorting(ind,type,direction) parameters worked.