Sorting not Working - Please can some one help

533 views
Skip to first unread message

Ravi Kura

unread,
Oct 5, 2014, 5:05:43 AM10/5/14
to jst...@googlegroups.com

I am very new to JQuery and JStree, i am trying to use Jstree and trying to sort the nodes. But system is not executing sort function. Please can you help in fixing the issue.

Here is the java script code and XXXXXXXXXX is variable replaced with JSON data for tree to be populated.


<script type="text/javascript"> 

$(function() { 

    $("#tree").on('changed.jstree', function (e, data) {

           var datainstance = data.instance.get_node(data.selected);

        changeProduct(data.selected,datainstance.original.attr.type);

    }).jstree(XXXXXXXXXX,{

    "sort" :  function (a, b) {

        alert("gggg");

        return get_node(a).original.attr.type > get_node(b).original.attr.type ? 1 : -1;

    }},

    {"plugins" : [ "sort"]});

});

System is displaying the tree view correctly and all nodes are correct, except sorting. Here sorting should be done based on type. 

See also the attached file of JSON and displayed tree below

Any help is very much appreciated


TreeStructure.json

Ivan Bozhanov

unread,
Oct 5, 2014, 7:44:03 AM10/5/14
to jst...@googlegroups.com
As I said on github - there is no way this will work:
jstree(XXXXXXXXXX,{

    "sort" :

The curly brace should not be there, please paste the real data - just use "view source" and paste all of the tree's config (remove the "data" part).

Best regards,

Ivan

Ivan Bozhanov

unread,
Oct 5, 2014, 7:46:22 AM10/5/14
to jst...@googlegroups.com
To make it clearer - the config should be something like this:
.jstree({
  "core" : {
    "data" : ...
  },
  "sort" : function (a, b) { ... },
  "plugins" : ["sort"]
});

Notice how "sort" is a "sibling" of "core", and not enclosed in its own curly braces.

Best regards,
Ivan
Reply all
Reply to author
Forward
Message has been deleted
0 new messages