Is it possible to add another column value, like id, in request when using inline()
Is it possible to add another column value, like id, in request when using inline()
![lsukharn](https://secure.gravatar.com/avatar/0d8e3af62a05f200563b230eac7c541b/?default=https%3A%2F%2Fvanillicon.com%2F0d8e3af62a05f200563b230eac7c541b_200.png&rating=g&size=120)
I am new to the Editor, so I am wondering how I can do the following:
$('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
editor.inline( this, 'additional column' );
} );
So in this case I am sending not only the edited cell data, like {'edited_cell': 100}, but additional information about the entry, like id. For example, the request would be {'id': 1, 'edited_cell': 100} now.
This additional column ('id') then can be used to update the right entry in the db.
Any help is much appreciated!
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Hi @lsukharn ,
The additional information, I believe, will go in the
submit()
call - take a look at the penultimate example which adds an extra field.This thread also talks about using
ajax.data
andpreSubmit
so there may be other avenues!Hope that helps,
Cheers,
Colin
@colin: I thought Editor automatically handles the 'id' field. Why is a separate column needed to update the db?
All correct![:) :)](https://datatables.net/forums/resources/emoji/smile.png)
The way Editor submits information is that the id field is implicit in the name of the parameter. e.g. consider submitting:
The id is
29
(with arow_
prefix to help avoid conflicts and make it a valid HTML4 id). To get that information on the server-side (if you aren't using the provided libraries) you'd need to loop over the data submitted and extract that information.The alternative, as Colin mentioned, is to use
ajax.data
orpreSubmit
to modify the data that is being submitted to the server (i.e. moving the loop from the server-side to the client-side to extract that data). The primary disadvantage of that (and why Editor doesn't do that) is that you loose the ability to do multi-row editing.To be clear, there is no need to have the id as an extra column (although you can do so if you want!).
Regards,
Allan
Allan, I found that iterating through request is the best solution, it also adds multi-row editing ability. I simply used:
However I encountered another another problem:
When I try to send only one value:
I don't know how to create a response that will update/refresh this value in DataTable.
So I get a response like this:
{data: [{'id': 'bla', 'cell1': 'value'}]}
, but the value doesn't get refreshed. So found a solution where I send all the row values and then return a response with all:This way the data refreshes w/o page refresh. It works, but looks a bit hacky.
Is there a way to send only the edited value in request and somehow form a response that will be rendered in the front end?
Hi @lsukharn ,
One option to reduce the traffic may be to use the 'allIfChanged' value on the submit option.
Cheers,
Colin
Yes, just to add to that, Editor currently requires that the whole data object for the row be returned from the server regardless of what field(s) are submitted. That is to allow for server-side updated fields such as last updated by etc.
We are going to relax that a bit in 1.8 to allow an individual field's data to be returned. Until then, if your server responds with all fields if you submit them all, that's a good work around.
Allan