Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82242

How do I define a data property for a column that is not from the ajax data source

$
0
0

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.


Viewing all articles
Browse latest Browse all 82242

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>