No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Sort datatable by number

    Help
    datatable desc sort
    2
    5
    2236
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • maximilianfixl
      maximilianfixl last edited by maximilianfixl

      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?

      1 Reply Last reply Reply Quote 0
      • benoitranque
        benoitranque last edited by benoitranque

        ...
        {
          label: 'ID',
          field: 'id',
          width: '4%',
          filter: true,
          sort: true,
          type: 'number'
        },
        ...
        
        1 Reply Last reply Reply Quote -1
        • maximilianfixl
          maximilianfixl last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • benoitranque
            benoitranque last edited by

            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

            1 Reply Last reply Reply Quote 0
            • maximilianfixl
              maximilianfixl last edited by

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post