Sort datatable by number



  • How can I sort q-datatable by default?
    For example I need to sort the ID column by DESC.
    I tryed to use the sort(a, b) method, but not successful.

    I tryed to use in columns array

    ...
    {
      label: 'ID',
      field: 'id',
      width: '4%',
      filter: true,
      sort (a, b) {
        return (a - b);
      },
      type: 'number'
    },
    ...
    

    Any ideas how to solve or explain it to me?



  • ...
    {
      label: 'ID',
      field: 'id',
      width: '4%',
      filter: true,
      sort: true,
      type: 'number'
    },
    ...
    


  • What makes it different than my code? That column sort’s ASC by id and not the other way round. I need to sort it from 999 on the top to 1 on the bottom. I was looking for the DESCENDING way.



  • Oh!

    Prety sure you can reverse the order by clicking. But for the sort function, simply reverse the order of the argumens bieng compared. so b - a instead of a - b



  • That’s what I tryed as well. But it has no effect. I go ahead! Will let you know, if I figured it out.


Log in to reply
 

Looks like your connection to Quasar Framework was lost, please wait while we try to reconnect.