I'm having a bizarre problem where I'm using identical code for two tables to retrieve the column index when the column header is clicked to change the sort. I'm doing this so I can display the sort field name in a printout. In one table it works perfectly and in the other the code for the event is never executed, as I've confirmed in the debugger. I'm using code that I found in this discussion:
https://datatables.net/forums/discussion/24593/retreive-column-idx-when-clicking-on-header. Is there something I'm not seeing here that would cause this issue?
First table (works perfectly):
$('#tblHerbs').on( 'click', 'thead th', function () {
var i;
i = dtHerbs.column(this).index();
switch (i) {
case 0: HerbSort = 'Herb Code'; break;
case 1: HerbSort = 'Herb Name'; break;
case 2: HerbSort = 'Gram Cost '; break;
case 3: HerbSort = 'Inventory'; break;
case 4: HerbSort = 'Low Inv.'; break;
case 5: HerbSort = 'Notes'; break;
}
});
Second table (nothing happens on click; this code is never reached):
$('#tblPatients').on( 'click', 'thead th', function () {
var i;
i = dtPatients.column(this).index();
switch (i) {
case 0: PatientSort = 'Name'; break;
case 1: PatientSort = 'Formula'; break;
case 2: PatientSort = 'Prescription Date'; break;
}
});