Ayoub Laazazi Ayoub Laazazi - 1 year ago 186
jQuery Question

JQuery edit DataTable Sort event

Is it possible to edit the sort event in

I want to change the color of table rows, when I sort a column, while they're already filtered by a search input.

"bSort":true, //this one
"aaSorting": [],


My working code:

"aaSorting": [],
"fnDrawCallback": function() {
console.log("Sort fired");

PS: added this.fnSettings().bSorted to detect what event is fired paging, filtering, sorting, etc.

Answer Source
  1. Possible to edit sort event: google "datatables sort event" and read the first link you find.
  2. Change color of table rows: google "datatables change default styling" and read the first link you find.
  3. When you sort a column: see #1.
  4. While they're already filtered by a search input: google "datatables check if filter is applied" and read the first link you find.

Once you've done this research and applied it to your problem, if you still aren't able to completely solve it, then you might post back with more specific questions about the problems that you're having.

One thing I'll explain for you since it isn't entirely obvious. Newer versions of DataTables have gotten away from all those obscure prefixes for options, and now just use a descriptive word. However, they kept the old versions for backward compatibility reasons. So, in your code example, paging is the newer version of bPaginate and they do the same thing. bSort is now orderable, aaSorting is now order, bInfo is now info, and bFilter is now searching. Since bFilter: false turns off the search capability, you probably want to remove it to get what you want, because "while they're already filtered by a search input" is not something that can exist when you've specified an option that removes the search input.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download