Pass a datatable column value to form input textbox onLoad of page
Pass a datatable column value to form input textbox onLoad of page

Assistance would be appreciated if I can address the below.
I'm trying to get the value from a datatable column ([8]) and pass it to the input form value within "defaultContent".
<script type="text/javascript" class="init">
$(document).ready(function() {
//var table = $('#carddetails').DataTable();
$('#carddetails').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "../test/processing.php",
"columnDefs": [
{ "bVisible": false,
"aTargets": [8]
},
{
"targets": -1,
"data": null,
"defaultContent": '<div class="btn-group"> <form action="../cardman/cardDetails?is=yes" method="post"><input name="cPan" type="text" id="cPan" value=""/><button type="submit" id="search" class="btn btn-info btn-xs dt-view" style="margin-right:16px;"><span class="glyphicon glyphicon-eye-open glyphicon-info-sign" aria-hidden="true"></span></button></form> <form><button type="button" class="btn btn-primary btn-xs dt-edit" style="margin-right:16px;"><span class="glyphicon glyphicon-print" aria-hidden="true"></span></button></form></div>'
}
],
//"aoColumnDefs": [{ "bVisible": false, "aTargets": [8] }]
"dom": 'Bfrtip',
"buttons": [
/* {
"extend": 'copy',
"text": '<i class="fa fa-files-o" style="color: green;"></i>',
"titleAttr": 'Copy',
"action": newexportaction
},*/
{
"extend": 'excel',
"text": '<i class="fa fa-file-excel-o" style="color: green;"></i>',
"titleAttr": 'Excel',
"action": newexportaction
},
{
"extend": 'csv',
"text": '<i class="fa fa-file-text-o" style="color: green;"></i>',
"titleAttr": 'CSV',
"action": newexportaction
},
{
"extend": 'pdf',
"text": '<i class="fa fa-file-pdf-o" style="color: green;"></i>',
"titleAttr": 'PDF',
"action": newexportaction
}/*,
{
"extend": 'print',
"text": '<i class="fa fa-print" style="color: green;"></i>',
"titleAttr": 'Print',
"action": newexportaction
}*/
]
} );
} );
</script>
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
This discussion has been closed.
Answers
Instead of using
columns.defaultContent
you will want to usecolumns.render
. This will give you access to the full row data. See this example.Kevin
Thank you for your assistance. That did the job.