how to render a column with with options generated via a loop in the data source
how to render a column with with options generated via a loop in the data source
i have my table's row generated through ajax:
ajax: {
url: 'xxx',
dataSrc: 'products'
},
my columns are set like this:
columns: [
{ data: 'cod' },
{ data: 'name' },
{ data: 'cost' },
{ data: 'weight' },
{
data: null,
defaultContent: '<select><option value="lotes.?.date">lotes.?.date</option></select>',
targets: -2
},
{
data: null,
defaultContent: '<input name="quantidade" class="form-control main-element" type="number" max="${produto.quantidadeTotal}" value="0" id="quantidade_${produtoId}" placeholder="Quantidade" />',
targets: -1
}
]
how could i generate the select tag with the options based on my data source's objects. The quantity of objects may vary from product to product.
Answers
Use
columns.render
to parse your data into select options. See this example. If you need further help then please build a simple test case that has an example of your ajax data so we can offer more specific suggestions.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin