Reputation: 313
I use JsTree with JsTreeGrid plugin. https://github.com/deitch/jstree-grid
I want to get parent node's Quantity to multiply it with current node's Quantity to obtain Extended quantity.
See code:
grid: {
columns: [
{header: "Title", value: function(node){return(node.text);}},
{width: 150, header: "Quantity", value: function(node){return(node.data.quantity);}},
{width: 150, header: "Extended Quantity",
value: function(node) {
return(get_parent(node).quantity*node.quantity);
}}
]
}
It gives me: Uncaught ReferenceError: get_parent is not defined
Upvotes: 0
Views: 602
Reputation: 3994
You will have to use the jstree instance to get the data for the parent node. The grid documentation does not seem to have a get_parent method. Here's one way to do the same by the getting the jstree instance & the parent node from that instance.
var oTree = $('#jstree_demo_div');
oTree.jstree({
"core": {
//...
//...
'data': data
},
grid: {
columns: [{ header: "Title", value: function (node) { return (node.text); } },
{ width: 150, header: "Quantity", value: function (node) { return (node.data.quantity); } },
{
width: 150, header: "Extended Quantity",
value: function (node) {
var parent = oTree.jstree(true).get_node(node.parent);
if(parent.hasOwnProperty('data')){ //Root node has no data
return (parent.data.quantity * node.data.quantity);
}
return(node.data.quantity);
}
}]
},
"plugins": ["grid"]
});
Upvotes: 1