Quasar: [Request] Set default sort column for DataTable

Created on 8 Feb 2017  路  6Comments  路  Source: quasarframework/quasar

Most helpful comment

All 6 comments

There is no methods except of refresh() for Data Table component.

As a workaround I can suggest only to simulate click on <th> of target column by it's index in .q-data-table-head table thead tr.

Like this:

let columnToSort = 0
document.querySelectorAll('.q-data-table-head table thead th')[columnToSort].click()

To reverse sort, I have to double-click it using timer 馃槅

@rstoenescu in the sort.js plugin for the datatables component, I think it would be a good idea to add sorting functionality for null values. As of now, if there is a null value in the column being sorted, sorting will fail because there is no localCompare property on a null string. I know you can add a sort function instead of a sort type, however I think this functionality would be better implemented by default. Here's a simple example for the string sort method.

If you think this is a good idea let me know and I'll make a pull request

Instead of
string: (a, b) => a.localeCompare(b)

It would be

(a, b) => {
   if (!a) {
       return -1
   }
   if (!b) {
       return +1
   }
   return a.localeCompare(b)
}

DataTable revamp is in progress for v0.15. It will include this. Thanks for your patience.

Closing as it's ready in future v0.15.

Url changed. You can now see how to do this here: https://quasar.dev/vue-components/table#QTable-API

Looking in the "Pagination" section for the "pagination" option.

For quick reference the 2 things you probably care about if you found this ticket are:

pagination = { sortBy: 'columnName', //string column name descending: true //boolean }

Was this page helpful?
0 / 5 - 0 ratings