Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I am using the angular datatables within my app. So far everything works well, except when I try to add custom sorting.

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

     $.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 just fine when tried on a standard table, but doesnt play nice with the angular app. When I click the heading of the table to sort - nothing happens. Console.log above yields blank values. Is there a way to use custom sorting with the angular directive?

share|improve this question

1 Answer 1

If table is generated using ng-repeat try this way in article OrderBy

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.