Can I find 'options' data when rendering a column in datatables?
Can I find 'options' data when rendering a column in datatables?
I'm trying to make a select in a column in a table. If I hardcode the options in the select it works, but I'd like to dynamically set them by looping thru the options object returned by the server(ajax). In the render function I have data, type and row available. Neither data or row will display 'options' when throwing them to console.log, so I guess there's no way for me to check options object and get those values at this stage, rendering column?
Below is hardcoded, so ignore what's inside each. You can probably see what I'm trying to do here, altough row obviously does not contain what I need?
{ data: null,
render: function(data, type, row){
var selHTML = '<select class="hSelType" id="seltype'+row.DT_RowId+'">';
$.each(row.options["holeactions.holeaction_typeid"], function(i, v){
selHTML += '<option value="1">Prod</option>';
selHTML += '<option value="2">Omb</option>';
selHTML += '<option value="3" disabled="true">Uppb</option>';
});
selHTML += '</select>';
return selHTML;
},
responsivePriority: 7,
className: "dt-center",
orderable: false
}
This question has an accepted answers - jump to answer
Answers
I'm afraid you don't have access to the full JSON object returned by the server at that point. You would need to make the Ajax call yourself and then use
data
to populate the table rather than using the DataTablesajax
option.Allan
Yes, I thought so...
I might use a select in a bubble instead, that works.