Combining Multiple Functions
Combining Multiple Functions
Hello, First timer with DataTables and loving it. I'm also not fluent in JS so I'm sure this is an easy one to resolve. I appreciate any help combining these two functions. I can get either one of the them to work by themselves, just having a heck of a time trying to merge them so both conditional formatting AND sorting/ordering both work and won't throw up the error...
"DataTables warning: table id=myTable - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3"
Here's my custom.js below...
$(document).ready(function () {
var table = $('#myTable').DataTable({
"createdRow": function( row, data, dataIndex ) {
if ( data[3] == "Cancelled" ) {
$(row).addClass('cancelled');
}
if ( data[3] == "Completed" ) {
$(row).addClass('completed');
}
if ( data[3] == "On Hold" ) {
$(row).addClass('onHold');
}
if ( data[3] == "In Progress" ) {
$(row).addClass('inProgress');
}
}
});
}
);
//SORT
$(document).ready(function () {
$('#myTable').DataTable({
order: [[1, 'desc']],
});
});
I also pasted the same code above into a text file here in case it helps...
https://site-proofs.com/MergedData.txt
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
Replies
You merge them like this:
Make sure to separate the options using a comma.
Kevin
Wow! That was easy. Really appreciate the help.
Yup, bloomin' genius is Kevin!
See also this section of the manual which might be of some use.
Allan