MicroDroid/vue-materialize-datatable

There is no way to define a column for default sorting

rodrigoAbril opened this issue · 8 comments

There is no way to define a column for default sorting

This should be a good place for improvement.

For now, try ordering the dataset outside the plugin on initial render

@MicroDroid I have tried, but when the tables render there are always some rows out of order.
In my case the first one will always be the row with id 57, but when i click to sort by id everyting fixes up....

I also noticed that the demo image in the documentation has the same error (first one is id 26)
687474703a2f2f692e696d6775722e636f6d2f313574417058752e706e67

@rodrigoAbril I understand that your question was asked nearly 2 years ago, but here is temporary solution:
in DataTable.vue find sortColumn data and change it to the column number you want your component to be sorted by on init.
@MicroDroid can we implement some new prop (:initSort=1/2/3/etc for example), which will change initial sorting?

:) seems like a good solution

@justice47 I'd rather find a better way since this is a controlled component and I'd rather not use local state with a prop like that.

@MicroDroid ok, if you will find a better way just post your thoughts about it, I can try to help you with that!

@MicroDroid maybe this approach will suit all needs:
Lets stay with sortColumn in data and change it only once, when component is mounted.
Example:
props

props: {
 ...,
 initSortCol: {default: 0}
}

data

data: () => ({
 ...,
 sortColumn: 0,
}

mounted hook

mounted: function() {
 ...
 this.sortColumn = this.initSortCol
}

and then in component call

<datatable
 ...
 :initSortCol="2"
>

Closed in #42