custom col sorting (taken from documentation) does not work

Hello, I have a problem with custom column sorting. I use the custom string sorting (case insensitive) from the documentation:

[code]

[/code]

Where is the mistake?

What do you mean under that sorting doesn’t work?
What result do you expect from the function?

I expect that by clicking on the column’s name, the rows will be sorted by this column’s entries, i.e. in this case sorted alphabetically (case insensitive). When I use some of the default sorting options, i.e. “str” in this case, it is perfectly working, both the command sort(…) and clicking on a column will successfully change the order of the rows in the grid. This is not the case with “str_custom”.

You need to init your function of custom sorting before the the page is loaded.

I don’t quite understand your answer - how can i initialize a function? Could you maybe tell me for the example I posted?
Thanks a lot!

ok. Here is the example that should work:

Just place your function str_custom out of function doOnLoad

[code]

[/code]

I’ve been trying this already before and just now again, it is still not working.
I really don’t see what should be wrong - this is done identically as in the documentation/samples and the example is really minimalistic.
Do you have any more ideas…? :confused:

Unfortunately the issue cannot be reconstructed.
Your html does well for us.
Please open ticket at support.dhtmlx.com/ and post a complete demo.

Did you really try the custom sorting? In your code above, the custom sorting is being commented out.

    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="codebase/dhtmlxgrid.css">
    <script src="codebase/dhtmlxcommon.js" type="text/javascript"></script>
    <script src="codebase/dhtmlxgrid.js" type="text/javascript"></script>
    <script src="codebase/dhtmlxgridcell.js" type="text/javascript"></script>
    <script type="text/javascript">

    //new place of function str_custom ()
      function str_custom(a,b,order){    // the name of the function must be > than 5 chars
        if (order=="asc")
          return (a.toLowerCase()>b.toLowerCase()?1:-1);
        else
          return (a.toLowerCase()>b.toLowerCase()?-1:1);
      }


    function doOnLoad() { 
      mygrid = new dhtmlXGridObject('gridbox');
      mygrid.setImagePath("codebase/imgs/");
      mygrid.setHeader("Item name,item_cd");

    // old place of function str_custom ()

      mygrid.setColSorting("str_custom,int"); // custom sorting does not work
      //mygrid.setColSorting("str,int"); // standard sorting works
      mygrid.setSkin("modern");
      mygrid.init();
      mygrid.loadXML("php/get.php", function() {
        mygrid.sortRows(0); // does not work
        //mygrid.sortRows(0, "str", "asc"); // standard sorting works
      });
    }
    </script>
    </head>
    <body onload="doOnLoad();">
    <div id="gridbox" style="width:600px;height:270px;overflow:hidden"></div>
    </body>
    </html>

So is this code (I just changed the comments) really working for you? If yes, could it be that I’ve been using old files (version 2.6)?
I can’t open a ticket as I just have the standard version.

Sorry for the typo in the previous post.

Your code works well for us.
Also see the attached screenshots.

If issue still occurs please try to update the version of your dhtmlxGrid





Hi,
I have the same problem. My function is defined in the separate js file (other functions in it are executed with no problems). But when I try to define the custom sorting like the author of this post, nothing happens. I tried to check sort executing within the code, and I find implementations for “str”, “int” and “date”(_sortCore function), but total ignore of other sort options.
Pls help - custom sorting is very important feature in my application.

10x a lot

Hello, custom sorting type is available in PRO version only