Quantcast
Viewing all articles
Browse latest Browse all 82110

Cannot sortor filter a dataTable when populating a table through AJAX / jSon.

Following the examples I am successfully populating a dataTable through AJAX / jSon. However, the sort, and filter features are not working.

Any assist in what I'm doing wrong would be GREATLY appreciated.

JS:
<script type="text/javascript" charset="utf-8">
var oTable;
var gaiSelected = [];

$(document).ready(function() {

/* Init the table */
oTable = $("#availUsersTable").dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource" : "SchedulingApi.do?dispatchto=getAvailableUsers&agencyCode="+agencyCode+"&allOfficers="+$('#SA_allOfficersCB').prop('checked'),
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
if ( jQuery.inArray(aData[0], gaiSelected) != -1 )
{
$(nRow).addClass('row_selected');
}
return nRow;
},
"aoColumns" : [
{ "mData": "firstName"},
{ "mData": "lastName"},
{ "mData": "type"},
{ "mData": "internalId"},
{ "mData": "shiftName"}
]
});

/* Click event handler */
$('#availUsersTable tbody tr').live('click', function () {
var aData = oTable.fnGetData( this );
var iId = aData[0];

if ( jQuery.inArray(iId, gaiSelected) == -1 )
{
gaiSelected[gaiSelected.length++] = iId;
}
else
{
gaiSelected = jQuery.grep(gaiSelected, function(value) {
return value != iId;
} );
}

$(this).toggleClass('row_selected');
} );
} );
</script>


HTML:
<div class="formDiv">
<table border="0" margin="0" padding="0" width="100%" class="dataTables_wrapper" id="availUsersTable">
<thead>
<tr> <th>First Name</th> <th>Last Name</th> <th>Type</th> <th>Id</th> <th>Shift</th> </tr>
</thead>
<tbody> </tbody>
</table>
</div>



JSON:
{
"aaData": [
{
"id": 146,
"type": "O",
"firstName": "Bob",
"lastName": "Jones",
"internalId": "4587",
"suffix": "",
"title": "",
"active": true,
"agencyCode": "OTHR",
"agencyDesc": "All Other",
"shiftId": null,
"shiftName": null,
"badgeNumber": "4587"
},
{
"id": 193,
"type": "O",
"firstName": "TempOfficer",
"lastName": "TempOfficerLN",
"internalId": "887456985",
"title": "",
"active": true,
"agencyCode": "OTHR",
"agencyDesc": "All Other",
"shiftId": null,
"shiftName": null,
"badgeNumber": "887456985"
},
{
"id": 178,
"type": "O",
"firstName": "Tester",
"lastName": "Test",
"internalId": "Test",
"title": "",
"active": true,
"agencyCode": "OTHR",
"agencyDesc": "All Other",
"shiftId": null,
"shiftName": null,
"badgeNumber": "Test"
},
{
"id": 194,
"type": "O",
"firstName": "TestOfficer2",
"lastName": "TestOfficerLN2",
"title": "",
"internalId": "654321987741258",
"active": true,
"agencyCode": "OTHR",
"agencyDesc": "All Other",
"shiftId": null,
"shiftName": null,
"badgeNumber": "654321987741258"
}
]
}

Viewing all articles
Browse latest Browse all 82110

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>