Categories | Question details Back To List | ||
stable sort with custom functions Hi, I have found your informations about custom sorting function and the hint about the unstable and stable sorting routine. Because I need the stable sorting I have called the enableStableSorting() function and get an error message. After integrating the patch provided in the post http://dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=4258&ssr=yes&s=enableStableSorting the stable sorting works fine in predefined sort orders (str, int...) But it doesn't work in custom functions like your str_custom or date_custom. Is there a possibility to use the stable sorting in custom sort functions? By the way: in your custom date sorting function is an error a=a.split("/") b=a.split("/") I think it must be a=a.split("/"); b=b.split("/"); isnt't it? Regards Dirk Answer posted by Support on Oct 08, 2008 10:14 >>isnt't it? Yes, documentation will be updated in nearest time. >>Is there a possibility to use the stable sorting in custom sort functions? For dhtmlxgrid 1.6+ the enableStableSorting affects both built-in and custom sorting functions ( not so sure for earlier versions ) The problem may be in sorting function , it need to be a bit more complex. function date_custom=function(a,b,order){ if (a==b) return 0; //the 0 must be returned for case, when values are equal a=a.split("/") b=b.split("/") if (a[2]==b[2]){ if (a[1]==b[1]) return (a[0]>b[0]?1:-1)*(order=="asc"?1:-1); else return (a[1]>b[1]?1:-1)*(order=="asc"?1:-1); } else return (a[2]>b[2]?1:-1)*(order=="asc"?1:-1); } Answer posted by Dirk Holstein on Oct 09, 2008 05:48 Now it works. Thanks for support. |