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)

fpc09111976fpc09111976 Posts: 2Questions: 1Answers: 0

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

  • fpc09111976fpc09111976 Posts: 2Questions: 1Answers: 0

    I used Object.keys() to get key by index but probably there are better solutions

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    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

This discussion has been closed.