Override Editor Data default function
Override Editor Data default function
Lucho_1312
Posts: 30Questions: 9Answers: 0
Hi!
Is it possible to override the default function used in the ajax data method?
I mean, I want to set up the Editor to work by default like this:
var editor = new $.fn.Editor( {
ajax: {
url: 'php/staff.php',
contentType: 'application/json',
data: function ( d ) {
return JSON.stringify( d );
}
}
} );
But I want to be able to setup the editor like this:
https://editor.datatables.net/examples/advanced/REST.html
editor = new $.fn.dataTable.Editor( {
ajax: {
create: {
type: 'POST',
url: '../php/rest/create.php'
},
edit: {
type: 'PUT',
url: '../php/rest/edit.php?id=_id_'
},
remove: {
type: 'DELETE',
url: '../php/rest/remove.php?id=_id_'
}
},
etc....
Thanks!
Luciano
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
That's because my REST server needs the data in JSON format, not as parameters.
Yes, simply use the extra parameters you need in the REST objects - e.g.:
Allan
Thanks!
I found something like that in a post here, so I made this (in case someone else needs something like me):
Using that, I can set all the table from html attributes (I'm trying to probe that making a jQuery plugin, I can set any dataTables + Editor just using data-* attributes, to make some tests with a NodeJS app)
So, the way I instance dataTables +editor is this:
and then using a plugin, I set everything in a generic way: