views:

37

answers:

0

This is my code :

$("#demo1").jstree({
        "themes": {
            "theme": "default",
            "dots": true,
            "icons": true,
            "url": "themes/default/style.css"
        },
        "ui" : {
                // this makes the node with ID node_4 selected onload
                "initially_select" : [ location.hash.slice(1).split('@')[1]]
            },
        "json_data" : {
            "data" : [
                { 
                    "data" : "A node", 
                    "children" : [ "Child 1", "Child 2" ]
                },
                { 
                    "attr" : { "id" : "li.node.id" }, 
                    "data" : { 
                        "title" : "Long format demo", 
                        "attr" : { "href" : "#" } 
                    } 
                }
            ]
        },
        "sort":function (a, b) { 
            return this.get_text(a) < this.get_text(b) ? 1 : -1; 
            },
        "contextmenu":{
                "show_at_node":false,
                "items":{
                        "sort" : {
                            // The item label
                            "label"             : "sort",
                            // The function to execute upon a click
                            "action"            : function (obj) { this.rename(obj); },
                            // All below are optional 
                            "_disabled"         : false,        // clicking the item won't do a thing
                            "_class"            : "sort",   // class is applied to the item LI node
                            "separator_before"  : false,    // Insert a separator before the item
                            "separator_after"   : true,     // Insert a separator after the item
                            // false or string - if does not contain `/` - used as classname
                            "icon"              : false,
                            "submenu"           : { 
                                "name":{
                                        "label"             : "name",
                                    },
                                "time":{
                                        "label"             : "time",
                                    }
                            }
                    }
            }
        },
        "core" : { "initially_open" : [ location.hash.slice(1).split('@')[0] ] },
        "plugins" : [ "themes", "json_data","crrm","ui","contextmenu","search","sort" ]
    })

i can change the sort function(when the tree loaded),

but, i can't find how to change the sort function when i right click and select the 'sort' option ?

thanks