question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Datatable - Default sorting (or no sort at all) / manual sorting

See original GitHub issue

It would be nice to be able to sort / keep items in order when loading the data.

Feature

I need to display the datatable sorted DESC using a field (which is the last one in the header list). I can’t find a way to do it (maybe I’m wrong). It’s an issue especially as the API returns everything in order and Vuetify sorts everything using the first column.

I think it’s not a edge case for my project, sorting is really important and at least it would be great to be able to keep the result sorted even if we want to have sortable columns.

Implementation I’m thinking about

Having a default-sort prop in the datatable component using the name property of the header and a direction.

<v-data-table :headers="headers" :items="results" default-sort="somefield:desc"></v-data-table>

or

<v-data-table :headers="headers" :items="results" sort-field="field" sort-desc="true"></v-data-table>

I could probably implement it if you think it’s good.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:11
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

85reactions
mchugh19commented, Mar 1, 2018

In case it helps anyone else looking for default sorting in a data table:

Create a data-table. Use hide-actions to not show the pagination tools at the bottom and bind pagination.sync to an object in your dataset.

<v-data-table
:items="items"
:headers="headers"
v-bind:pagination.sync="pagination"
hide-actions
item-key="items.key"
>

In your data, create a pagination key with a object. To display all rows, use the rowsPerPage value of -1.

pagination = {'sortBy': 'column2', 'descending': true, 'rowsPerPage': -1}

This will sort by column2 ascending and display all items

7reactions
nekosaurcommented, Aug 1, 2017

Take a look at example 7 in the docs to see how you could do manual sorting and/or default sorting. You need to use the pagination.sync prop.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a way to disable initial sorting for jquery DataTables?
Here is the solution: "aaSorting": [[ 2, 'asc' ]], 2 means table will be sorted by third column, asc in ascending order. The...
Read more >
Remove default sorting of first column — DataTables forums
Hi guys,. I want to know how to remove default sorting(ordering) of first column for dataTable. Thanks in advance. Thanks,
Read more >
Multi-column sorting - DataTables example
As you would expect with a desktop application, DataTables allows you to sort by multiple columns at the same time. This multiple sorting...
Read more >
Data Grid - Sorting - MUI X
Sorting is enabled by default to the grid users and works out of the box without any explicit configuration. Users can set a...
Read more >
Sort a Column with a Custom Order in Power BI - RADACAD
Having a reference table, that you have one value per row for EnglishEducation is perfect because then it is easier to set up...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found