Categories | Question details Back To List | ||
dhtmlxGrid - Sort on Hidden Column I have previously asked if it's possible to sort data on a column that is hidden. So I click on (visible) Column X in a grid and it sorts the rows according to data in (hidden) Column Y. The answer I got was as follows (where X and Y are replaced by the relevant column indexes): grid.attachEvent("onHeaderClick",function(ind){ if (ind == X){ grid.sortRows(Y,"str","asc"); return false; } return true; }); There are a couple of issues with this solution. Firstly, it always sorts in ascending order due to the hardcoded 3rd parameter in the sortRows call. I realise that this was an example but how can I tell what the current sort order is for a particular column? Once I know that, I can then toggle it ("asc"->"des" and "des"->"asc") and pass this as the 3rd parameter. However, what I have found is when the data is sorted, the direction indicator image is not displayed in the Column Header. I think this is down to the return false after the call to grid.sortRows. I think it might be missing some further code down the line because when I return true, the image comes back - but the sorting on the hidden column is overwritten. By the way, this has all come about because I cannot get "date" sorting to work!! I saw another KB article somewhere saying that date sorting occurs using the standard javascript Date.Parse function. It said that this requires that the date is in MM/DD/YYYY format. My data is in DD/MM/YYYY format - standard UK date format. Would this be the cause of "date" sorting to not work? If the above method does not work, how can I modify the standard "date" sorting so that it works with DD/MM/YYYY dates. I cannot use custom sorting because I am using the Standard edition. I see there is a setDateFormat function available in the Pro edition. Does this allow the grid to hold the physical data in one format but to display it formatted? Answer posted on Nov 13, 2007 05:17 Please check http://dhtmlx.com/docs/products/kb/index.shtml?cat=recent&q=1182 which covers part of your questions >>If the above method does not work, how can I modify the standard "date" sorting so that it works with DD/MM/YYYY dates. In code of dhtmlxgrid there are next two rows var aVal = Date.parse(arrTS[a.idd])||(Date.parse("01/01/1900")); var bVal = Date.parse(arrTS[b.idd])||(Date.parse("01/01/1900")); those two lines are date parsing for sorting, you may replace it with any other code which will create comparable objects (int, string, etc ) from your data >>I see there is a setDateFormat function available in the Pro edition. >>Does this allow the grid to hold the physical data in one format but to display it formatted? This can be applied for date based excell only ( limited support for "calendar" excell and pretty rich date formating support for "dhxCalendar" excell ) |