Viewing 4 replies - 16 through 19 (of 19 total)
  • Thread Starter KingShinobi

    (@kingshinobi)

    yes, now the empty cells are on the bottom, but two other issues came up with that.

    1. it only sorts on the first digit ?? eg. 1, 12, 2, 25, 3

    2. if i add the other custom command from before those commands (only asc sorting and sorting disabled on some columns) don’t work.

    “aoColumnDefs”: [ { “bSortable”: false, “aTargets”: [ 1, 3, 5, 7, 9, 11,13 ] }, { “asSorting”: [ “asc” ], “aTargets”: [ “_all” ] } ], “bSortClasses”:true, “aoColumnDefs”: [ { “sType”: “mystring”, “aTargets”: [ “_all” ] } ]

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    1. Yeah, that’s because everythings is sorted as strings. Here’s another try:

    jQuery.extend( jQuery.fn.dataTableExt.oSort, {
    	"numeric-empty-bottom-asc": function ( x, y ) {
    		if ( "" == x ) return 1;
    		if ( "" == y ) return -1;
    		return parseFloat( x ) - parseFloat( y );
    	},
    	"numeric-empty-bottom-desc": function ( y, x ) {
    		if ( "" == x ) return 1;
    		if ( "" == y ) return -1;
    		return parseFloat( x ) - parseFloat( y );
    	}
    } );

    I also rewrote that into a better and more modern syntax, and renamed the sort type to something that makes more sense.

    2. Merging these “Custom Commands” requires a little bit more:

    "bSortClasses":true, "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 1, 3, 5, 7, 9, 11, 13 ] }, { "asSorting": [ "asc" ], "aTargets": [ "_all" ] }, { "sType": "numeric-empty-bottom", "aTargets": [ "_all" ] } ]

    Regards,
    Tobias

    Thread Starter KingShinobi

    (@kingshinobi)

    wohoo! ?? the code works. the only thing i noticed is, if you click on the sorted column again, the empty cells change their order. this is not a real problem, i just wanted to give you feedback.

    thank you so much for all your help!

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    great to hear that this worked! ??

    Yes, I can imagine that the empty rows than change order, but I have no idea how to prevent that, sorry ??

    Best wishes,
    Tobias

Viewing 4 replies - 16 through 19 (of 19 total)
  • The topic ‘ignore empty cells when sorting asc’ is closed to new replies.