How to Override Editor Remove to Act Exactly Like Editor Edit

How to Override Editor Remove to Act Exactly Like Editor Edit

doborshdoborsh Posts: 1Questions: 0Answers: 0
edited April 2013 in Editor
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.

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    It shouldn't be empty there - I've just tried it with my local examples and `data` has `data.data[]` which is an array of the row ids, as you indicate. You should then be able to manipulate the `data` object as you need before it is sent to the server.

    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
  • jontxujontxu Posts: 3Questions: 0Answers: 0
    edited May 2013
    Hi,
    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.
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Hi jontxu,

    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
  • jontxujontxu Posts: 3Questions: 0Answers: 0
    Thanks Allan, I fixed it with that option.

    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.
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    edited May 2013
    Thanks for the feedback. If I may ask then, how did you get a copy of Editor without downloading it from the Editor web-site? I'm curious, although I should also say that it is commercial software. To use it beyond the 15 day trial period, it needs to be paid for (purchasing the software allows me to support it in the forums like this).

    Allan
  • jontxujontxu Posts: 3Questions: 0Answers: 0
    edited May 2013
    I think it was an example on the web. At first I thought of testing it because I tried other alternatives (didn't work). I tried it and it is indeed great.

    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".
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Heh - thank you :-). Its much appreciated, and I'm glad you are enjoying using Editor!

    Allan
This discussion has been closed.