mmik
mmik

Reputation: 6011

JsTree-grid doesn't display the data

I'm working with the JsTree Ajax lazy load feature and to display the data I am using JsTree-grid. However, I am having the issue with display the data using the JsTree-grid on the second column. I've the following JSON data that I'm passing through the PHP using the JsTree ajax lazy load feature:

[    
    {
        "id": ​157749,
        "parent": "Sheet1.worksheet1webs44lx8GbsHu9igMc2vM_qWJqhePuo257PKZm_6Uo",
        "text": "Script 1: Login",
        "data": {
            "status": "Fail"
        }
    },
    {
        "id": ​104511,
        "parent": "Sheet1.worksheet1webs44lx8GbsHu9igMc2vM_qWJqhePuo257PKZm_6Uo",
        "text": "skip",
        "data": {
            "status": "Pass"
        }
    }
]

In the Javascript I've the following code:

$('#jstree').jstree({
    plugins: ['grid'],
        'grid': {
             'columns': [
                 {
                     'width': 50,
                     'header': 'Nodes'
                 },
                 {
                     'width': 30,
                     'header': 'Status',
                     'value': function (node) {
                         return (node.status);
                     }
                 }
             ]
         },
         'core' : {
             'data' : {
                 "url" : function (node) {
                     return node.id === '#' ? 'node' : 'tree/' + node.id;
                 },
                 'data' : function (node) {
                     return { 'id' : file.id, 'title' : file.title };
                 },
                 "dataType" : "json"
             }
         }
     });

Note: When I console log the node on here: 'value': function (node) { console.log(node); } I got the following result on the console:

Object { status: "Fail" }
Object { status: "Pass" }

I would like to display the status Pass or Fail on the second JsTree-grid column. However, the JsTree-grid isn't displaying the data and I'm even not getting any error on the console. Please, can someone help me regarding what I want to achieve.

Upvotes: 1

Views: 1816

Answers (1)

Nikolay Ermakov
Nikolay Ermakov

Reputation: 5061

I see two issues here:

  1. "parent": "Sheet1.worksheet1webs44lx8GbsHu9igMc2vM_qWJqhePuo257PKZm_6Uo"; your json doesn't have any parents for these nodes
  2. you don't need function here - 'value': function (node) { return (node.status); }, simply use 'value': 'status'.

After fixing these two issues it works, check demo - Fiddle.

Upvotes: 1

Related Questions