I'm using DataTables with a jQuery UI accordion.
I have code which fills the Datatable with data (vis json) when the accordion section is opened, but this doesn't align the header correctly.
Table definition
$('#tblSuppContacts').dataTable({
"autoWidth":false
, "footer": false
, "info":false
, "JQueryUI":true
, "language": {"emptyTable":"No Contacts For Supplier"}
, "ordering":true
, "paging":false
, "scrollY":"325px"
, "scrollCollapse": true
, "columnDefs": [
{ className: "LeftNoWrap", "targets": [ 1,2,3,4,5,6,7 ] }
, { className: "RightNoWrap", "targets": [ 0 ] }
]
});
This is the code which fires when the accordion section opens which checks if the table has any rows before reading it.
var table = $('#tblSuppAddress').DataTable();
if ( ! table.data().any() ) {fncSuppAddressRead();}
Then this codes loads the data into the table.
if ( $.fn.DataTable.isDataTable('#tblSuppContacts') ) {
$('#tblSuppContacts').DataTable().clear();
}
var dTable = $('#tblSuppContacts').DataTable();
for (var i = 0; i < pData.length; i++) {
dTable.row.add([
fncFormatNumber(pData[i].REF,0,"N")
,trim(pData[i].NAME)
,trim(pData[i].DEPARTMENT)
,trim(pData[i].POSITION)
,trim(pData[i].PHONE)
,trim(pData[i].FAX)
,trim(pData[i].COMMENT)
,trim(pData[i].EMAIL)
]);
}
$('#tblSuppContacts').DataTable().draw();
}
When i click on the table header, the columns headers then line up correctly with the data columns.
