Custom sorting with dwatables angular directive

I am using angular datatables in my application. So far, everything is working fine, except when I try to add custom sorting.

I have a dataset that returns a hyphen, "-" if there is no data. Here is my sorting ::

$.fn.dataTableExt.oSort['nullable-asc'] = function(a,b) { if (a == '-') return 1; else if (b == '-') return -1; else { var ia = parseInt(a); var ib = parseInt(b); return (ia<ib) ? -1 : ((ia > ib) ? 1 : 0); } } $.fn.dataTableExt.oSort['nullable-desc'] = function(a,b) { console.log(a,b) if (a == '-') return 1; else if (b == '-') return -1; else { var ia = parseInt(a); var ib = parseInt(b); return (ia>ib) ? -1 : ((ia < ib) ? 1 : 0); } } ..start controller... vm.dtColumnDefs = [ DTColumnDefBuilder.newColumnDef(0).notSortable().withClass('hidden-print') DTColumnDefBuilder.newColumnDef(1).withClass('td-fieldname'), //name DTColumnDefBuilder.newColumnDef(2), //fieldType DTColumnDefBuilder.newColumnDef(3).withOption('type', 'html-num-fmt'), DTColumnDefBuilder.newColumnDef(4).notSortable(), //distribution DTColumnDefBuilder.newColumnDef(5).withOption('type', 'html-num-fmt'), //cardinality DTColumnDefBuilder.newColumnDef(6).withOption('type', 'nullable'), //Min DTColumnDefBuilder.newColumnDef(7).withOption('type', 'nullable') //Max ]; ...other angular code..... 

This works great when trying to use a standard table, but does not work with the angular app. When I click on the table heading to sort, nothing happens. Console.log above gives empty values. Is there a way to use custom sorting using the angular directive?

+6
source share

Source: https://habr.com/ru/post/985083/


All Articles