Dhtmlxgrid does not sort on page load

Hi guys,

I have problem to make dhtmlxgrid sort on page load.

this is my code:

[code]var mygrid = new dhtmlXGridObject('mygrid_container');
mygrid.setImagePath("http://192.168.10.89/assets/tools/dhtmlx/imgs/");
mygrid.setHeader("Name,Date,Text");
mygrid.setInitWidths("130,130,*");
mygrid.setColAlign("right,right,left");
mygrid.setSkin("light");
mygrid.setColSorting("str,str,str");
mygrid.setColTypes('ro,ro,ro');
mygrid.sortRows(0,"str","des");
mygrid.init();[/code]

No matter what I did, the first column refuse to sort on page load. I change ‘des’ to ‘asc’, and vice versa and nothing change. the table displays data by ‘Date’ column asc as far as I see.

Feedback and/or guidances are highly appreciated.

Thanks

You need to call sortRows() method after all rows are loaded:

load(url,function(){ mygrid.sortRows() })

I have

	mygrid.load(url, "json");
	mygrid.sortRows(1,"str","des");

till, it does not work.

I did a little experiment by doing the following:

var jon = {
			"rows": [
				{ "id" : "1",
				"data": [ "John Smith", "2011-04-11 10:34:58","first note #1"]
				},
				{ "id" : "2",
				"data": [ "Michael Mizo", "2011-04-11 15:59:50", "mikes note"]
				},
			]
		};
	mygrid.parse(jon,'json');
	mygrid.sortRows(1,"str","des");

the data is the same as getting from the url. Why parse/sortRows work but the load/sortRows does not ?

I solved it. What I am missing is the callback inside the load.


	 mygrid.load(url, function() {
		 mygrid.sortRows(1,"str","des");
	 }, 'json');

I have a similar problem but i’m not able to solve it.

The sort doesn’t work in my grid.
That’s my code:

var grid_1 = a.attachGrid();
grid_1.setIconsPath('imgs/');
grid_1.setHeader(["Apellidos","Nombre","Población"]);
    grid_1.setColumnIds("APELLIDOS,NOMBRE,POBLACION");
grid_1.setColTypes("ro,ro,ro,ro");
    grid_1.setInitWidths('*,*,*');
grid_1.setColSorting('str,str,str');
   grid_1.sortRows(1,"str","asc");
grid_1.init();

grid_1.sync(dataClientes);

I use a datastore.
What do you think is the problem ??

In case of using datastore you may need to add the following code:

grid_1.sync(dataClientes,{ sort:true});