How I can get the row identifier when edit in a rest call (PUT)
How I can get the row identifier when edit in a rest call (PUT)
This is a part of my datatable editor definition:
edit: {
type: 'PUT',
url: 'https://api.mydomain.com/countries/code/_id_',
dataType: "json",
contentType: "application/json; charset=utf-8",
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Bearer " + auth_token);
},
data: function (country) {
return JSON.stringify(country.data[HERE!!!!]);
}
}
country have this value: {"action":"edit","data":{"AL":{"code":"AL","name":"Albania"}}}
I need to get the row id that is stored in id and contains the value "AL" that is the primary Key of the row.
Thank you for help
Answers
I used Object.keys() to get key by index but probably there are better solutions
Yes, DataTables needs the data to be in an array, not an object. So you'd need to loop over the object keys in some way
Object.keys()
is one option for that.Allan