Insert two json data to custom columns

Insert two json data to custom columns

coisoxcoisox Posts: 4Questions: 3Answers: 0
edited May 2017 in Free community support

I have 3 columns. I need the last column to have data from the first two columns

dt = $('#datatables').DataTable({
    ajax: "api/getData.php",
    columns: [
        { "data": "id" },
        { "data": "desc" },
        { "data": null, "defaultContent":
            '<div id="'+data.id+'">'+data.desc+'</div>'
        }
    ]
});

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    base on https://datatables.net/reference/option/columns.render do this

    dt = $('#datatables').DataTable({
        ajax: "api/getData.php",
        columns: [
            { "data": "id" },
            { "data": "desc" },
            { "data":null, 
               render: function (data, type, rowData, meta){
                   return  '<div id="'+rowData.id+'">'+rowData.desc+'</div>';
                }
            }
        ]
    });
    
  • coisoxcoisox Posts: 4Questions: 3Answers: 0

    Thank you. Its working. And I also take a look at the link you gave but your example is much clearer.

This discussion has been closed.