Categories | Question details Back To List | ||
Grid with csv upload not sorting Here is the code- what is missing? It was sorting- then- stopped. I am sure I missed something. var mygrid; function doInitGrid(){ mygrid = new dhtmlXGridObject('mygrid_container'); mygrid.setImagePath("images/"); mygrid.setHeader("Date,Name,City,ST,Type,Dscrpt,Price,Mech"); mygrid.setInitWidths("50,215,100,50,70,175,150,50"); mygrid.setColAlign("right,left,left,left,left,left,right,left") mygrid.setSkin("modern"); mygrid.setColSorting("date,str,str,str,str,str,int,str"); mygrid.setColTypes("ro,ro,ro,ro,ro,ro,price,ro"); // mygrid.attachEvent("onRowSelect,doOnRowSelectro); mygrid.init(); mygrid.load("transaction.csv", "csv"); } The csv file looks like: ,10/28/08,Bank of America Corporation ,Charlotte ,NC ,Purchase ,Preferred Stock w/Warrants ,15000000000,Par ,10/28/08,Bank of New York Mellon Corporation ,New York ,NY ,Purchase ,Preferred Stock w/Warrants ,3000000000,Par ,10/28/08,Citigroup Inc. ,New York ,NY ,Purchase ,Preferred Stock w/Warrants ,25000000000,Par ,10/28/08,The Goldman Sachs Group, Inc. ,New York ,NY ,Purchase ,Preferred Stock w/Warrants ,10000000000,Par Answer posted by dhxSupport on Mar 26, 2009 02:52 When you load grid from csv format first column in the csv file is recognized as row's ids. In you case first column hasn't unique id's. That's wy sorting doesn't work. You can enable mode, where ID for rows loaded from CSV autogenerated: mygrid.enableCSVAutoID(true); To use this method you should include file codebase/ext/dhtmlxgrid_nxml.js. In this case your csv file should looks like that: 10/28/08,Bank of America Corporation ,Charlotte ,NC ,Purchase ,Preferred Stock w/Warrants ,15000000000,Par Also, if you want to implement sorting by date, your column should has "calendar", "dhxCalendar" or "dhxCalendarA" type. http://www.dhtmlx.com/docs/products/dhtmlxGrid/samples/cell_types/calendar_grid.html Answer posted by blake on Mar 30, 2009 13:39 I too am having the same difficulty as the OP. I tried the advice listed, but no matter what I try, am unable to sort. My first columns is unique, and whether I try enableCSVAutoID or not, results are the same. No sorting. 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"); } |