Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Brad Konia on May 21, 2008 12:08
open dhtmlx forum
Grid Default Sort

I created a grid using dhtmlxGrid 1.6 and by default, I want the grid to be sorted by the first column. The sort works fine if the user manually clicks on the column header, but I can't get it to initially display with the first column sorted. Here's the code I'm using to initialize the grid:

<script type="text/javascript">
mygrid = new dhtmlXGridObject('browseCams');
mygrid.imgURL = "/include/dhtmlxGrid/imgs/";
mygrid.setHeader("Category, Description, Cams Online");
mygrid.setInitWidths("150,450,100");
mygrid.setColTypes("ro,ro,ro");
mygrid.setColAlign("left,left,center")
mygrid.setColSorting("str,str,int");
mygrid.setSkin("modern");
mygrid.enableRowsHover(true, 'mouseover');
mygrid.enableAutoHeight(true);
mygrid.init();
mygrid.load('browse_cams_xml.php');
mygrid.sortRows(0);
</script>

My expectation was that mygrid.sortRows(0) would make it initially display with the first column sorted, but that doesn't seem to work.
Answer posted by Support on May 22, 2008 02:23
Grid loading is async., which means that the command next to the load will be executed in moment when data not loaded yet, the correct syntax will be
You can use onXLE event or second parameter of load function to achieve desired behavior

mygrid.load('browse_cams_xml.php',function(){
    mygrid.sortRows(0);
});