How to Override Editor Remove to Act Exactly Like Editor Edit
How to Override Editor Remove to Act Exactly Like Editor Edit
Great idea that the DataTable's editor sends an array of IDs to the web service to delete when data.action === 'remove'. Unfortunately we have already established our web services to act exactly like the editor edit function (ie: sending a JSON payload of data). So how can I override the editor remove process to act exactly like edit below?
[code]
} else if (data.action === 'edit') {
$.ajax({
"type": method,
"contentType": "application/json; charset=utf-8",
"url": url,
"data": JSON.stringify({
CT2_ID: data.data.CT2_ID.toString(),
NAME: data.data.NAME.toString(),
DESCRIPTION: data.data.DESCRIPTION.toString(),
DATA_VALUE: data.data.DATA_VALUE.toString(),
UPDATED_BY: data.data.UPDATED_BY.toString()
}),
"dataType": "json",
"headers": {
"APIAuthorization": "AuthID",
"APIEnvironment": "DEV",
"APIVersion": "1.00"
},
"success": function (json) {
successCallback(json);
},
"error": function (xhr, error, thrown) {
errorCallback(xhr, error, thrown);
}
});
[/code]
I tried using
[code]
editor.on('onPreSubmit', function (e, data) {
if (data.action === 'remove') {
alert(JSON.stringify(data));
}
});
[/code]
but data is empty.
This is our only open item left with the editor.
[code]
} else if (data.action === 'edit') {
$.ajax({
"type": method,
"contentType": "application/json; charset=utf-8",
"url": url,
"data": JSON.stringify({
CT2_ID: data.data.CT2_ID.toString(),
NAME: data.data.NAME.toString(),
DESCRIPTION: data.data.DESCRIPTION.toString(),
DATA_VALUE: data.data.DATA_VALUE.toString(),
UPDATED_BY: data.data.UPDATED_BY.toString()
}),
"dataType": "json",
"headers": {
"APIAuthorization": "AuthID",
"APIEnvironment": "DEV",
"APIVersion": "1.00"
},
"success": function (json) {
successCallback(json);
},
"error": function (xhr, error, thrown) {
errorCallback(xhr, error, thrown);
}
});
[/code]
I tried using
[code]
editor.on('onPreSubmit', function (e, data) {
if (data.action === 'remove') {
alert(JSON.stringify(data));
}
});
[/code]
but data is empty.
This is our only open item left with the editor.
This discussion has been closed.
Replies
If you want to completely override the Ajax call that Editor makes, you can use the `ajax` option ( http://editor.datatables.net/options/#ajax ).
Regards,
Allan
I'm trying the same workaround as doborsh but using it for all the actions, like this:
[code]
"ajaxUrl": {
"create": "/lectures/new/" + name,
"edit": "/lectures/update/" + name,
"remove": "/lectures/delete/" + name
},
"ajax": function ( method, url, data, successCallback, errorCallback ) {
$.ajax( {
"type": method,
"url": url,
"data": JSON.stringify({
lecname: data.data.lecname.toString(),
lectitle: data.data.lectitle.toString(),
ename: data.data.ename.toString(),
sdate: data.data.sdate.toString(),
edate: data.data.edate.toString(),
lecturer: data.data.lecturer.toString(),
excerpt: data.data.excerpt.toString(),
location: data.data.location.toString()
}),
"dataType": "json",
"success": function (json) {
successCallback( json );
},
"error": function (xhr, error, thrown) {
errorCallback( xhr, error, thrown );
}
});
},
//...
[/code]
But that way it appears as undefined. I'm not using the row_id parameter, i'm using database indexes instead. But I can't delete anything in the database (it does in the table, though) because in the request there is no data.
I'm using node.js as backend and without changing the AJAX settings adding new elements and editing it works.
You can use the `idSrc` option to tell Editor what parameter to read the row identifier (usually the db table's primary key). I'd also say, don't both using JSON.stringify for the data -just give jQuery an object and let it deal with it.
Beyond that, I think we'd need a link to a test case.
I don't actually have a record of a trial or purchased license of Editor for yourself? Are you using it under some else's account? So I can ensure my records are up-to-date.
Thanks,
Allan
About the license, let me explain:
I'm currently a last year college student and I'm doing an end of degree project (at least it's like this in Spain). I was trying different grid style methods. I tried the basic datatable with jEditable but it didn't work. I saw this and I stumbled upon an example and I tried it.
Now that you commented that, I saw the free trial but the presentation of the project is in June. I could ask my employer (I'm in an intership) to pay for the license, but it's 80€ and I don't know if it'd be profitable... I'll try, though.
I'm sorry.
Allan
I'm going to ask my employer if it can be purchased, because It's supposed that the project is sponsored in the company because i'm an intern there. I hope they accept, It'd be great for all parties.
I also don't want to be sort of a "pirate".
Allan