Reputation: 168
I'm having trouble showing several values from different fields in the database in the datatable. The code I have from the table is:
var listar = function () {
var table = $('#customers-table-view').DataTable({
destroy: true,
ajax: {
method: 'POST',
url: 'listar'
},
columns: [
...
{'data': 'service1'},
...
],
In the database I have service1, service2, service3 ... on or off. What I would like is to get those values in the same column. That is to say that in the cell something like that remained; On, Off, Off ...
Upvotes: 0
Views: 3766
Reputation: 4674
If you want to display a custom value on DataTables column, you might want to use the columns.render
property. You can pass a function that returns a text or even an HTML element.
On your case, this might look something like this:
$('#customers-table-view').DataTable({
columns: [
...
{
data: 'service1',
render: function (data, type, row, meta) {
return row.service1 + ', ' + row.service2 + ', ' + row.service3
}
},
...
]
});
Hope this gives you an idea.
Upvotes: 3