Pass columns.render Via Ajax
Pass columns.render Via Ajax
lunarcrm
Posts: 2Questions: 1Answers: 0
I'm generating my datatables on the fly, writing the columns and data using a single function. I'm wanting to pass in the columns.render values directly from my ajax data but I'm getting parser errors when I try to do this. Here is my code...
var data,
jqxhr = $.ajax($url).done(function () {
data = JSON.parse(jqxhr.responseText);
$('#json').text(JSON.stringify(data));
$(tableName).dataTable({
"data": data.data,
"columns": data.columns[0]
});
})
And this is the data I'm passing in...
{
"data": [
[
"Column",
"250.00"
]
],
"columns": [
[
{
"name": null,
"className": "sml",
"total": null
},
{
"name": "Leads",
"className": "smlr",
"orderable": true,
"render": function ( data, type, row, meta ) { return 'Link'; }
}
]
]
}
I've also tried enclosing the render function in double quotes but this returns as requested unknown parameter error.
Thanks
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I think you will find this thread interesting:
https://datatables.net/forums/discussion/comment/128096/#Comment_128096
Kevin
The tread was useful thanks. I adapted it and used the following is anyone is interested.
{
"data": [
[
"Column",
"250.00"
]
],
"columns": [
[
{
"name": null,
"className": "sml",
"total": null
},
{
"name": "Leads",
"className": "smlr",
"orderable": true,
"function": "myfunction(data, type, row, meta)"
}
]
]
}
function myFunction(data, type, row, meta) {
return data + " " + type + " " +row + " " + meta;
}