When using Ajax with jQuery DataTables, how do I determine what to do with the data returned?

Short Answer For your specific question, you were very close with dataSrc: “accounts:account”. Instead, it needs to be dataSrc: “accounts.account” – using a dot instead of a colon. This is standard JavaScript dotted object notation for navigating down through the levels of a JSON structure. So: ajax: { url: “./get_all_accounts.php”, dataType: “JSON”, // not actually … Read more

Datatables: Change cell color based on values

First of all, initialize DataTable only once. Then as per your question, use rowCallback and not fnRowCallBack as shown below: var oTable = $(‘#countryTable’).DataTable({ ‘rowCallback’: function(row, data, index){ if(data[3]> 11.7){ $(row).find(‘td:eq(3)’).css(‘color’, ‘red’); } if(data[2].toUpperCase() == ‘EE’){ $(row).find(‘td:eq(2)’).css(‘color’, ‘blue’); } } }); Here’s a fiddle

JQuery Datatables search within input and select

It is not very well documented. And it seems to work differently, or not work at all, between (sub)versions. I think dataTables is intended to automatically detect HTML-columns, but for some reason, most of the times, it doesnt. The safest way is to create your own search-filter : $.fn.dataTableExt.ofnSearch[‘html-input’] = function(value) { return $(value).val(); }; … Read more

TypeError: $(…).DataTable is not a function

CAUSE There could be multiple reasons for this error. jQuery DataTables library is missing. jQuery library is loaded after jQuery DataTables. Multiple versions of jQuery library is loaded. SOLUTION Include only one version of jQuery library version 1.7 or newer before jQuery DataTables. For example: <script src=”https://stackoverflow.com/questions/31227844/js/jquery.min.js” type=”text/javascript”></script> <script src=”js/jquery.dataTables.min.js” type=”text/javascript”></script> See jQuery DataTables: Common … Read more

dataTable() vs. DataTable() – why is there a difference and how do I make them work together?

Basically, the two constructurs return different objects. dataTable constructor var table = $(<selector>).dataTable() dataTable is the oldschool dataTables constructur, which returns a jQuery object. This jQuery object is enriched with a set of API methods in hungarian notation format, such as fnFilter, fnDeleteRow and so on. See a complete list of API methods here. Examples … Read more

datatable jquery – table header width not aligned with body width

CAUSE Most likely your table is hidden initially which prevents jQuery DataTables from calculating column widths. SOLUTION If table is in the collapsible element, you need to adjust headers when collapsible element becomes visible. For example, for Bootstrap Collapse plugin: $(‘#myCollapsible’).on(‘shown.bs.collapse’, function () { $($.fn.dataTable.tables(true)).DataTable() .columns.adjust(); }); If table is in the tab, you need … Read more

How print in Jquery / Datatables [closed]

First, you should NEVER post minimized code – it’s not easy to read, and therefore, it’s hard for people to answer your question. This will lead to a negative scoring question. Datatables are pretty easy to use, and there are plenty of examples at their website (datatables.net) for this. For this particular problem, try https://datatables.net/examples/basic_init/hidden_columns.html … Read more