Row Data
Row Data
I'm not having any issues. This is more of a question on the inner workings of how row data works. Here is a source example.
HTML
<table id="gvDATA" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th></th>
<th>Due Date</th>
<th>Purchase Order</th>
<th>Part</th>
</tr>
</thead>
</table>
INITIALIZATION
$('#gvDATA').DataTable({
lengthMenu: [[10, 50, 100, -1], [10, 50, 100, "All"]],
data: _PurchData.d.responseData,
columns: [
{ data: "ChangeColumn", orderable: false },
{ data: "DUE_DATE"},
{ data: "PURCHASE_ORDER", "width": "7%" },
{ data: "PART" },
{ data: "RRN", "visible": false, className: "noVis"}
],
dom: 'Blfrtip',
buttons: [
{
extend: 'copyHtml5',
exportOptions: {
columns: ':visible'
}
},
{
extend: 'colvis',
columns: ':not(.noVis)'
}
]
});
GETTTING ROW DATA
var _mytable = $("#gvDATA").DataTable();
var _rowdata = _mytable.row(_rowindex).data();
// Set the Ajax Parameters
var _RRN = _rowdata.RRN;
Here is my question. I did not define a column for RRN in the html, but I did define RRN in the initialization. I don't see RRN when I view the HTML, but I can see RRN when I get the row data. This is exactly what I'm wanting to do. My question is where is the row data stored if I can't see it in the html ?
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
Answers
I'm surprised you aren't getting an error. Take a look in your browsers console. Datatables expects the number of columns in the
thead
to match the number defined incolumns.data
. You have 4 defined in yourthead
and 5 incolumns.data
. For theRRN
column you can usecolumns.visible
to hide that column.Datatables has a data cache which it stores all the table data that is in the client. Datatables takes over the HTML display of the table and only the rows shown on the page are actually in the HTML. When you search, sort or go to the next page Datatables uses the data cache to determine which rows to display and updates the HTML as appropriate. When you use something like
row().data()
Datatables will pull the data from its data cache.HTH,
Kevin
I checked chrome, firefox, and edge. I'm not getting any errors in the console. Interesting.
I went ahead and added the columns in thead to match. It works either way. Thanks.
DataTables is creating the HTML for the extra column in the original code above, and then hiding it, which is why you can't see it.
As Kevin says that isn't needed here. DataTables stores a "reference" to the original row data object, so you can use any data point you want from it for the display in the table. You don't need to reference the data in a column to have it retained in the data object, since it is the original data object.
Allan