I am trying to modify the original value from pst_no
to a new value in the input tag
{
title: "Old amount",
data: "pst_no" // This is from server
},
{
title: "New Amount",
data: "pst_no", // I want to name this attribute to a custom name, not from the data source
"render": function (data, type, row, meta) {
if (type === 'display') {
data = '<input id="newPostNo" type="number" value="' + data + '" />';
}
return data;
}
}
Then, I am trying to obtain both values. Here is how I have tried so far
let arr = [];
let rows = $('tr.selected');
let newValue = $('tr.selected#newPostNo');
let rowData = myTable.rows(rows).data();
$.each($(rowData), function (key, value) {
arr.push({
old: value['pst_no'],
new: value[newValue]
});
})
console.log(JSON.stringify(arr)); // This prints [{"old":"1"}]
I did try giving custom data like title: "New Amount", data: "new_pst",
and getting it like new: value['new_pst'],
but got undefined
.
How do I solve this? Thanks for reading.