How do I get the value of a hidden column?
How do I get the value of a hidden column?
patreeeeek
Posts: 14Questions: 7Answers: 0
This is how I generate my datatable:
$(document).ready(function () {
$('#datatables').DataTable({
"dom": '<"toolbar">frtip',
"responsive": true,
"scrollY": "550px",
"scrollCollapse": true,
"ajax": "smsMessages.json",
"aoColumns": [
{"mData": "sender"},
{"mData": "content"},
{"mData": "receiveTime"},
{"mData": "messageId"},
{"mData": "messageId",
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("<i class='ti-pencil-alt btn btn-simple btn-edit btn-icon' data-target='#replyModal' data-toggle='modal' data-mode='edit'></i>\n\
");
}
}
],
language: {
"search": "_INPUT_",
searchPlaceholder: "Search records"
}
});
This is how I access the content
$('#datatables tbody').on('click', '.btn-edit', function () {
var dt = $('#datatables').DataTable();
var data = dt.cells($(this).closest('td').siblings().eq(0)).data();
var data2 = dt.cells($(this).closest('td').siblings().eq(1)).data();
var data3 = dt.cells($(this).closest('td').siblings().eq(2)).data();
var data4 = dt.cells($(this).closest('td').siblings().eq(3)).data();
var sender = data[0];
var message = data2[0];
var dateR = data3[0];
var messageId = data4[0];
var dateRe = new Date(dateR);
alert(messageId);
dateReceived = moment(dateRe).format("MM/DD/YYYY hh:MM A");
$('#sender').val(sender).change();
$('#message').val(message).change();
$('#dateReceived').val(dateReceived).change();
});
I've tried to do this
{"mData": "messageId","visible":false},
but once I do, it will return undefined
if you guys have any other suggestions on how I can do this it would be of great help
This discussion has been closed.
Answers
Hi @patreeeeek ,
Yep, the column isn't in the DOM so you can't use jQuery to access those values. A hidden column is still available through the API so you can use the data functions to get the values back - there's a few based on table/column/row/cell - i.e.
data()
/column().data()
/row().data()
/cell().data()
Cheers,
Colin
This question is done.
reference: https://stackoverflow.com/questions/43505999/get-the-values-from-jquery-datatable-hidden-columns
You're welcome...