generated content for a column with Ajax data source from objects

generated content for a column with Ajax data source from objects

AnahouaAnahoua Posts: 2Questions: 1Answers: 0

I have a problem with generated content for a column, it is not working when using Ajax data source from objects, the buttons do not get rendred in the table. here my initialization code for the table:

var table = $('#example').DataTable( {
"ajax": 'http://localhost/two/test/api2',
"columns": [
{ "data": "name" },
{ "data": "adress" },
{ "data": "ID" }
],
"columnDefs": [ {
"targets": -1,
"data": null,
"defaultContent": "<button>Click!</button>"
} ]
} );

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,364Questions: 26Answers: 4,777
    edited June 2017 Answer ✓

    Maybe this will work for you:

    var table = $('#example').DataTable( {
      "ajax": 'http://localhost/two/test/api2',
      "columns": [
        { "data": "name" },
        { "data": "adress" },
        { "data": "ID" },
        { "data": null, "defaultContent": "" }
      ],
      "columnDefs": [ {
        "targets": -1,
        "createdCell": function(td, cellData, rowData, row, col) {
               $(td).prepend(
                 "<button>Click!</button>"
               );
             }
         } ]
    } );
    

    Sorry if there is syntax errors :smile:

    Kevin

  • AnahouaAnahoua Posts: 2Questions: 1Answers: 0

    Thank you for your help :)

This discussion has been closed.