ColumnDefs did not get called
ColumnDefs did not get called
alextang
Posts: 9Questions: 2Answers: 0
I have the following code
$("#datatable").dataTable({
"ajax": {
"url": "http://some data source/",
"dataSrc" : "",
"columnDefs": [ {
"render": function ( data, type, col ) {
return data +' ('+ col[3]+')';
},
"targets": 0
} ]
}
});
My Ajax data is just an array without the "data" attribute. I can see the data retrieved and displayed on the data table. However, the columnDefs was never called. Please help.
Also, there is data returned which I don't want to display. I assume I will need to create another columnDefs for that column and set visible to false?
This discussion has been closed.
Replies
The columnDefs shouldn't be inside the Ajax definition. It should be either above or below it, unless I'm missing something huge here.
I honestly don't even know what it is that you're trying to do with columnDefs there, columnDefs defines the columns you want in the table, it doesn't really have anything to do with the actual data being retrieved and it's nowhere defined inside the ajax documentation http://datatables.net/reference/option/ajax.
Thanks, Rpiechura! It works now after I moved it outside the Ajax. I used the columnDefs mainly to render Ajax returned data (i.e. add icon and other stuff to it). In addition, I wanted to use it to hide unwanted data by using the "visible" : false in the column definition.
Yeah, I got that, I just didn't understand why you had it inside the Ajax call, but the answer is that it was a mistake, glad you got it to work though. =)