How to add html input select to JSON generated table.

How to add html input select to JSON generated table.

bededebedede Posts: 3Questions: 1Answers: 0

I have the tables working using a local variable holding object data called "dataApproved", this will eventually be a remote JSON file. There is a requirement to include in the last column a select input. I have read /examples/api/form.html however the example is using hardcoded table. How do I mix data sources, I cannot add html syntax into the JSON objects. Was looking at column.defs etc to append a new column after the table is built using the JSON. Here is my thinking but not working. I could step out of Datatable.js and append with Jquery, but thought there would be a way inside the library.

var inputSelect = "<select>~~~~~</select>"

$('#approvedRequests').DataTable( {
//ajax: 'activityData.json',
data: dataApproved,
responsive: { 
            },
            columns: [
                { data: 'request' },
                { data: 'reason' },
                { data: 'start' },
                { data: 'end' },
                { data: 'duration' },
                { data: 'note' },
                { data: 'action' },
                {inputSelect}
            ],


        } );

Replies

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49

    One way to achieve this is using the following code for your {inputSelect}

    {
         "data"      : null,
         "render"    : function (row, type, data) {
              return (html);
         }
    }
    
This discussion has been closed.