Ordering of column that contains HREF tags that are integers not ordering correctly

Ordering of column that contains HREF tags that are integers not ordering correctly

tonykotonyko Posts: 13Questions: 7Answers: 0
edited August 2020 in Free community support



Description of problem: I'm trying to order the table on column 1, which contains href tag with integer id's. It orders it like its a string, placing 29 before 9.

I'm using datatables 1.1.10. When I look up this question, it states that this new datatables version should be able to automatically handle this, but it does not for me.

I've also tryed setting "type":"html" and "type":"html-num" which on first load, sets the ordering correctly but does not work when I toggle the order changing icon.

If there is anything I am missing in my setup, or any thing I may have overlooked, please let me know.

Answers

  • kthorngrenkthorngren Posts: 22,376Questions: 26Answers: 5,139

    Use Orthogonal Data to return the number for the sort and type operations. Something like this pseudo code:

        render: function ( data, type, row ) {
            // Return the numeric value for the `sort` and `type` detection operations
            if ( type === 'sort' || type === 'type' ) {
                var val = Number( parse `data` to extract the numeric value )
                return val;
            }
            // Return the original data for the `display` and `filter` operations
            return data;
        }
    

    Kevin

This discussion has been closed.