How popular a datatable to json

How popular a datatable to json

bkfsecbkfsec Posts: 2Questions: 1Answers: 0
edited March 2015 in Free community support

Hi, I have the following format Json:
[{"idComponent":1,"idComponentLabel":"C1","componentName":"COMPONENT","description":"COMPONENT","isAssignedComponent":true}, {"idComponent":2,"idComponentLabel":"C2","componentName":"COMPONENT2","description":"COMPONENT2","isAssignedComponent":true}]
as popular a datatable

Answers

  • allanallan Posts: 62,858Questions: 1Answers: 10,344 Site admin

    Use ajax.dataSrc and set it to be an empty string. Then use columns.data to tell each column what property to use for that column.

    See the data section of the manual for more information.

    Allan

  • bkfsecbkfsec Posts: 2Questions: 1Answers: 0
    edited March 2015

    Sorry I try to be clearer. I have a String with this format

    [
        {
            "idComponent": 1,
            "idComponentLabel": "C1",
            "componentName": "COMPONENT",
            "description": "COMPONENT",
            "isAssignedComponent": true
        },
        {
            "idComponent": 2,
            "idComponentLabel": "C2",
            "componentName": "COMPONENT2",
            "description": "COMPONENT2",
            "isAssignedComponent": true
        }
    ]
    

    And I'm trying to populate the table as follows

    var componentSystem   = '<s:property escape="false" value="componentSystemTableString"/>';
        alert(componentSystem);
        
        
        $('#componentTable').dataTable({
            "data": componentSystem,
            "columns": [
                            {
                               "data" : null,
                               "fnRender" : function(oObj){
                                  return "<center><input class='datatable_checkbox' type='checkbox' id='"+oObj.aData.idComponent+"' name='componentSevedCheckbox' checked='checked' onChange='saveComponentSevered(\""+oObj.aData.idComponent+"\",this);'/></center>";
                                    
                                }
                          }, 
                          {"data": "componentName"},
                          {"data": "description"}
                          ]
                    
            
        });
    
  • allanallan Posts: 62,858Questions: 1Answers: 10,344 Site admin

    First thing to note is that fnRender was removed in 1.10 so that isn't going to work. Use columns.data and columns.render instead.

    Beyond that, what you have looks like it should work okay.

    Allan

This discussion has been closed.