Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted on Mar 31, 2009 05:37
open dhtmlx forum
CSV grid not sorting

I too am having the same difficulty as a previous poster (link: http://www.dhtmlx.com/docs/products/kb/index.shtml?q=8762). Reposting here because it looks like my addon question wasn't seen. I tried the advice listed, but no matter what I try, am unable to sort.
My first column is unique, and whether I try enableCSVAutoID or not, results are the same. No sorting.

plain.csv:
,HEADER1,HEADER2,HEADER3,HEADER4,HEADER5,HEADER6
,a_item1,a_item2,a_item3,a_item4,a_item5,a_item6
,b_item1,b_item2,b_item3,b_item4,b_item5,b_item6
,c_item1,c_item2,c_item3,c_item4,c_item5,c_item6
,d_item1,d_item2,d_item3,d_item4,d_item5,d_item6
,e_item1,e_item2,e_item3,e_item4,e_item5,e_item6
,f_item1,f_item2,f_item3,f_item4,f_item5,f_item6

grid code:
function createGrid()
{
mygrid = new dhtmlXGridObject('excelGrid');

mygrid.setImagePath("../js/dhtmlxGrid/codebase/imgs/");
mygrid.loadCSVFile("plain.csv");
//mygrid.enableCSVAutoID(true);
mygrid.enableCSVHeader(true);

mygrid.setInitWidths("130,130,130,130,130,130");
//mygrid.setColAlign("left,left,left,left,left,left");
//mygrid.setColTypes("ro,ro,ro,ro,ro,ro");
mygrid.setColSorting("str,str,str,str,str,str");

mygrid.enableAutoWidth(true,800,799);
mygrid.enableAutoHeight(true,500,499);

mygrid.setSkin("modern");
mygrid.init();

mygrid.load("plain.csv","csv");
}
Answer posted by Support on Mar 31, 2009 07:51
The problem caused by double initialization. 
You specifying some parameters through javascript and structure of grid headers defined in CSV in same time. 
Grid can be configured from js script , or directly from datasource, but not the both in same time. In you case grid configured on client side, and after that reset because of header line in CSV ( and related js command ) 

To solve issue you can 
a) define header in js code and remove mygrid.enableCSVHeader(true); line

or 
b) reorganize existing js code as
mygrid.loadCSVFile("grid.csv",function(){
    mygrid.setColSorting("str,str,str,str,str,str"); 
});

In such case , sorting settings will be applied to grid only after data loaded ( so they will not be reset by header line in CSV )