ServerSide filtering and null data
ServerSide filtering and null data
If if turn on server side Processing and try to filter on a table that has a column that has a null value it triggers and error :
Here is my code:
$('#view_affiliates_details').DataTable( {
dom: "Tfrtip",
ajax: {
url: "../php/affiliates.php",
type: "POST"
},
serverSide: true,
columns: [
{ data: "affiliates.name" },
{ data: "affiliates.contact_email" },
{ data: "affiliates.contact_mobile_number" },
{ data: "affiliates.contact_number_2" } ,
{
data: null,
className: "center",
defaultContent: '<a href="#" class="editor_edit button blue">Edit</a> <a href="#" class="editor_remove button red">Delete</a>'
}
],
tableTools: {
sRowSelect: "os",
aButtons: [
{ sExtends: "editor_create", editor: editor },
{ sExtends: "editor_edit", editor: editor },
{ sExtends: "editor_remove", editor: editor }
]
},
initComplete: function ( settings, json ) {
editor.field( 'affiliates.company_branches_id' ).update( json.company_branches );
}
} );
When I do a simple filter I get an error that unknown field index(4). If I remove the server side processing i am able to filter. How can this be fixed?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The error should link you to this tech note. There are details there, but basically if you have
null
data, you need to tell DataTables what to do with it.columns.defaultContent
can be used for this.Allan
Thank you. I have fixed it doing this:
I am sorry Alan. I blundered. During other tests I realized that the code above did not fix the issue. You suggested I use the columns.defaultContent , which I am already using but still experiencing the same error:
I found the answer from a similar post that was answered recently here:
http://datatables.net/forums/discussion/24231/null-column-serverside-search-error#latest
its amazing how simple it is to implement some of these features. However finding the correct reference some times is difficult. Answer:
Good to hear you got it working.
I would be interested to know if you have any suggestions on how I can improve the documentation for finding answers. Obviously I know where to look since I wrote it, so any feedback would be welcome.
Allan