jQuery DataTables TableTools Export - get values of checkboxes or radio items
jQuery DataTables TableTools Export - get values of checkboxes or radio items
dreadedmanraz
Posts: 24Questions: 5Answers: 0
I am using TableTools v2.2.2 and DataTables 1.10.0 and have it successfully exporting some table contents. However, it is not picking up the values from the checkboxes in the table cells. How can I extract the value as true or false (or 1,0; any indicator really) from the cells and make them export?
table = $('#sort1').DataTable({
stateSave: true,
filter: false,
"order": [[sortColumn, "asc"]],
"pageLength": 25,
"columnDefs": [
{
"targets": ['no-sort'],
"orderable": false,
},
],
"autoWidth": false,
"tableTools": {
"aButtons": [
{
"sExtends": "collection",
"sButtonText": "Export",
"aButtons": ["csv", "xls", "pdf", "print"],
// TODO: Get this working.
"fnCellRender": function ( sValue, iColumn, nTr, iDataIndex ) {
return " TableTools";
}
}
],
"sSwfPath": "/Scripts/plugin/datatables/TableTools/swf/copy_csv_xls_pdf.swf"
},
"initComplete": function (oSettings, json) {
$(this).closest('#sort1_wrapper').find('.DTTT.btn-group').addClass('table_tools_group').children('a.btn').each(function () {
$(this).addClass('btn-sm btn-default btn-primary');
});
if ($('td.dataTables_empty')) {
$('td.dataTables_empty').parent().hide();
}
},
// This sets the resulting html layout i.e. https://datatables.net/reference/option/dom
"dom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-6 hidden-xs'lT>r>" +
't<"dt-toolbar-footer"<"col-sm-6 col-xs-12 hidden-xs"i><"col-xs-12 col-sm-6"p>><"clear">"'
});
<table class="table table-bordered table-condensed table-hover table-responsive table-striped dataTable" id="sort1" aria-describedby="sort1_info" role="grid">
<thead>
<tr role="row"><th style="vertical-align: bottom; width: 1%;" class="no-sort sorting_disabled" rowspan="1" colspan="1" aria-label="">
<input id="include" name="include" type="checkbox" value="true"><input name="include" type="hidden" value="false">
</th><th style="vertical-align: bottom; width: 20%;" class="sorting_asc" tabindex="0" aria-controls="sort1" rowspan="1" colspan="1" aria-sort="ascending" aria-label="&nbsp;: activate to sort column ascending"> </th><th class="center no-sort sorting_disabled" rowspan="1" colspan="1" aria-label="Tax Agent">Tax Agent</th><th class="center no-sort sorting_disabled" rowspan="1" colspan="1" aria-label="AFSL">AFSL</th><th class="center no-sort sorting_disabled" rowspan="1" colspan="1" aria-label="Auditor">Auditor</th><th class="center no-sort sorting_disabled" rowspan="1" colspan="1" aria-label="Bankruptcy">Bankruptcy</th><th class="center no-sort sorting_disabled" rowspan="1" colspan="1" aria-label="Liquidator">Liquidator</th><th class="center no-sort sorting_disabled" rowspan="1" colspan="1" aria-label="BAS Agent">BAS Agent</th><th class="center no-sort sorting_disabled" rowspan="1" colspan="1" aria-label="SMSF Auditor">SMSF Auditor</th><th class="center no-sort sorting_disabled" rowspan="1" colspan="1" aria-label="CPA">CPA</th><th class="center no-sort sorting_disabled" rowspan="1" colspan="1" aria-label="ICAA">ICAA</th><th class="center no-sort sorting_disabled" rowspan="1" colspan="1" aria-label="CPA Certificate">CPA <br>Certificate</th><th class="center no-sort sorting_disabled" rowspan="1" colspan="1" aria-label="ICAA Certificate">ICAA <br>Certificate</th></tr>
</thead>
<tbody>
<tr role="row" class="odd">
<td class="center">
<label class="checkbox">
<input checked="checked" class="checked" data-val="true" data-val-required="The Include field is required." id="AggregEntities_07c8ac97-6984-4f5a-b5bb-8d60888aaccf__Include" name="AggregEntities[07c8ac97-6984-4f5a-b5bb-8d60888aaccf].Include" type="checkbox" value="true"><input name="AggregEntities[07c8ac97-6984-4f5a-b5bb-8d60888aaccf].Include" type="hidden" value="false">
<i></i>
</label>
</td>
<td class="sorting_1">
ACS Corporate Group
- <b><i>Anthony Bray</i></b>
</td>
<td class="center">
<span class="onoffswitch">
<input class="onoffswitch-checkbox" id="AggregEntities_07c8ac97-6984-4f5a-b5bb-8d60888aaccf__TaxAgent_Switch" name="AggregEntities[07c8ac97-6984-4f5a-b5bb-8d60888aaccf].TaxAgent.Switch" readonly="readonly" type="checkbox" value="true"><input name="AggregEntities[07c8ac97-6984-4f5a-b5bb-8d60888aaccf].TaxAgent.Switch" type="hidden" value="false">
<label class="onoffswitch-label" for="Switch">
<span class="onoffswitch-inner" data-swchon-text="Yes" data-swchoff-text="No"></span>
<span class="onoffswitch-switch"></span>
</label>
</span>
</td>
//.............................................................//
</tr>
</tbody>
</table>
You can see I've been trying to use fnCellRender and its anoynmous method, but even though I expect it to return " TableTools" for each cell, it returns nothing.
Thanks, Rhys
This discussion has been closed.