Order by

Order by

nvargo83nvargo83 Posts: 2Questions: 1Answers: 0
edited January 2017 in Free community support

I am having trouble figuring out how to order by just numbers only.
I would like DataTables to ignore ordering by stock_code and only sort by stock_number is row stock_number
Any help is appreciated!

                "order": [[ 0, "desc" ]],
                "columns": [
                    {
        "data": "stock_number",
        render: function ( data, type, row ) {
        return row.stock_code+ +row.stock_number;
    }
},
                    { "data": "year" },
                    { "data": "make" },
                    { "data": "model" },
                    { "data": "date" },
                    { "data": "vin" },
                    { "data": "miles" },
                    { "data": "cost" },
                    { "data": "who" }
        ]

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 22,239Questions: 26Answers: 5,116

    Not sure what the data looks like but maybe you can use the Natural sorting plugin.

    Kevin

  • nvargo83nvargo83 Posts: 2Questions: 1Answers: 0

    Sorry "stock_code" is letters and "stock_number" is numbers only. I would like it to only sort by numbers and ignore all letters.

  • kthorngrenkthorngren Posts: 22,239Questions: 26Answers: 5,116
    edited January 2017

    Try the Natural sorting plugin. It works for me to sort data in that format,

    Kevin

  • allanallan Posts: 64,925Questions: 1Answers: 10,753 Site admin
    Answer ✓

    The other option would be to use the rendering function to make use of DataTables' orthogonal data:

    render: function ( data, type, row ) {
      if ( type === 'type' || type === 'sort' ) {
        return row.stock_number;
      }
      return row.stock_code+ +row.stock_number;
    }
    

    Allan

This discussion has been closed.