Simple form output without data[row_x][field]=value
Simple form output without data[row_x][field]=value
chrisxaustin
Posts: 8Questions: 3Answers: 0
Is there a standard way to use a simple form output for single-row editing?
e.g. https://editor.datatables.net/examples/advanced/REST.html
Sample form data:
action:edit
data[row_19][first_name]:Bradley
data[row_19][last_name]:Greer
data[row_19][position]:Software Engineer
data[row_19][office]:London
data[row_19][extn]:2558
data[row_19][start_date]:2012-10-13
data[row_19][salary]:132000
I would prefer
first_name:Bradley
last_name:Greer
position:Software Engineer
office:London
extn:2558
start_date:2012-10-13
salary:132000
I can do this using ajax.data to pull the first value from the data array, e.g.
ajax: {
url: '/save',
data: function(data) {
var out = Object.values(data.data)[0]
return out
}
},
But this feels a little dirty. Is there a more standard way?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Using
ajax.data
to manipulate the data sent to the server is basically the only way. There is thelegacyAjax
option which will flatten the data and send it in adata
object. That was changed in 1.5 which introduced multi-row editing since that scheme doesn't provide any ability to support multi-row editing.Normally I would suggest using
$.extend()
sinceObject.values()
isn't supported by old IE, but if you have the luxury of not worrying about that -Object.values()
is perfect.I have wondered about having an option in Editor that would allow the data to be submitted in different ways and have two or three of the most common ones built in (such as this). But the problem with that is that any example given that uses
preSubmit
orajax.data
could be very misleading, resulting in a lot of confusion.It is something I continue to think about though!
Regards,
Allan