Categories | Question details Back To List | ||||||||
problems with custom sorting First of all, thx for answering all my earlier questions. Now i have another one: I have a grid showing some data about projects. In one view the projects are ordered by their start date, so the starting date column is the tree column. The date is shown in a format like dd.mm.yyyy and next to the date a number shows how many projects started at this day. So it looks like 10.01.2008 (5) for example. Because JS cant sort a date like this i implemented an own custom sort function. Here is my code: myGridbox.setHeader("Start Date, ProjectNr, Status, Site, Product, Cell, Short Description, Owner, End Date, Mod. Date"); myGridbox.setColTypes("tree,link,img,ro,ro,ro,ro,ro,calendar,calendar"); myGridbox.setColSorting("sort_custom,str,str,str,str,str,str,str,date,date"); myGridbox.setCustomSorting(sort_custom,1); // (dont know if this one is necessary but i included it, doesnt make a difference anyway) Here is the sort function: function sort_custom(a,b,order) { dateA = a.slice(3,13).split("."); dateB = b.slice(3,13).split("."); yearA = dateA[2]; monthA = dateA[1]; dayA = dateA[0]; yearB = dateB[2]; monthB = dateB[1]; dayB = dateB[0]; if (yearA == yearB) { if (monthA == monthB) { if (order == "asc") { return dayA <= dayB ? 1 : -1; } else { return dayA > dayB ? 1 : -1; } } else { if (order == "asc") { return monthA < monthB ? 1 : -1; } else { return monthA > monthB ? 1 : -1; } } } else { if (order == "asc") { return yearA < yearB ? 1 : -1; } else { return yearA > yearB ? 1 : -1; } } } Well, the rows are sorting correctly, but the problem is that i have to click twice instead of once on column header to get it sorting. So it is only sorting when the descending arrow is shown, but one time it sorts ascending, the other time descending. Well, thats not a great thing, but the real problem is: If the rows are sorted ascending, but it is shown the descending arrow and i want to open the first row for example, it sorts the rows immediately descending and the first row moves to last position. I have to fix this, so i would very appreciate it, if you maybe know, what the problem could be. Thx a lot!! Answer posted on Jan 10, 2008 02:11 >>myGridbox.setCustomSorting(sort_custom,1); // (dont know if this one is
necessary but i included it, doesnt make a difference anyway) because you already set custom sorting on previous line, this one is not necessary, but will not cause any harm. Unfortunately I can't reconstruct same problem locally - you sorting function works correctly for me ( please check attached sample ) Which version of dhtmlxTreeGrid do you use ? Attachments (1)
Answer posted by Wolfgang Philipp on Jan 10, 2008 04:07 I am using TreeGrid version 1.4. Strange that it is working on your local machine, it is not working here. Strange thing about is that i think it worked once. Should there be the site loading when you click on the header to sort it? I think i remembered site was loading when it was working but it doesnt now. Your sample is working fine, it works as intended, so that you only have to click once on the header. Thx Answer posted by Wolfgang Philipp on Jan 10, 2008 05:41 I have another question. When i include an alert message in my own sort_custom function (like alert ("xxx")) it doesnt appear. So does it mean the function is not executed? Or is it ok, that there is no output? Should i post the whole code maybe? thx Answer posted by Support on Jan 10, 2008 07:55 >>it doesnt appear. So does it mean the function is not executed? Or is it ok, that there is no output? If any row exists in grid - sorting function must be called and alert from it will be executed. If you don't see alert - there are only two possible reasons - there is no rows in grid - sorting not executed at all Sorting can be blocked by returning false|null from onBeforeSort event. If problem still occurs for you - please send any kind of sample to support@dhtmlx.com |