Hidden field values not accessible through DataTable.
Hidden field values not accessible through DataTable.
I am trying to create nested grid.
where on click I am trying to create table and show it below the row.
I was able to add Table but d[9] & d[10] were undefined. d[2] able to access because that field was present in column but d[9] & d[10] were hidden in actual table hence not able to access.
Please provide me Help on how to access Hidden field in this case.
Note: I have used ASPX page in background and able to bind successfully with Database.net.
$('#ctl00_ctl00_MasterPageContent_MainContent_grdViewInvolvedVehicle tbody').on('click', 'td.sorting_1', function () {
var tr = $(this).closest('tr');
var row = table.row( tr );
if ( row.child.isShown() ) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child( format1(row.data()) ).show();
tr.addClass('shown');
}
} );
function format1 ( d ) {
// `d` is the original data object for the row
return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;border:0px">'+
'<tr>'+
'<td style="padding-left:5px;"><b>ABC</b><br />Hello-' +d[2]+'</td>'+
'<td style="padding-left:5px;"><b>PQR</b><br />'+d[9]+'</td>'+
'<td style="padding-left:5px;"><b>XYZ</b><br />'+d[10]+'</td>'+
'</tr>'+
'</table>'+
'</td>'+
'</tr>'+
'</table>';
}
This question has an accepted answers - jump to answer
Answers
<asp:TemplateField Visible="false">
<ItemTemplate>
<%# Eval("ITEMID") %>
</ItemTemplate>
</asp:TemplateField>
Tag I am using to hide column
Its hard to say without actually seeing it or at least seeing an example of your data. When using
format1(row.data())
you are passing the row data to the function not the column data being displayed. My suggestion is to place some debugging statements in yourformat1()
function to see whatd
is. For example:If this doesn't help please post a link to your page or a test case replicating the issue. This way we can see what you have to provide suggestions.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
@kthorngren , Thanks for response.
Yes I tried the same, d is giving columns which are bind and visible on UI. But it is not giving any value for hidden fields.
Without seeing what you are doing its hard to say what the problem is.
d
will contain the original data set for Datatables. Again please provide a link to a test case so we can see what you are doing.Kevin
attached local debugging screenshots
If you can't post a test case then please post your datatables config.
Are you using a DOM based table?
Does this place the column in the HTML as hidden or is not part of the DOM when Datatables initializes? You can use the browser's inspect tool to find out.
Here is a simple example of a hidden column and Datatables picks up the data:
http://live.datatables.net/vewunaje/1/edit
If the above column is not in the DOM then maybe you let Datatables hide the column using
columns.visible
.Kevin
@kthorngren , Thanks a lot.
Link you provided in your comment really helped me.