MicroDroid / vue-materialize-datatable

A fancy Materialize CSS datatable VueJS component.
https://overcoder.dev/vue-materialize-datatable
MIT License
179 stars 67 forks source link

There is no way to define a column for default sorting #26

Closed rodrigoAbril closed 5 years ago

rodrigoAbril commented 6 years ago

There is no way to define a column for default sorting

MicroDroid commented 6 years ago

This should be a good place for improvement.

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

rodrigoAbril commented 6 years ago

@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

justice47 commented 5 years ago

@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?

rodrigoAbril commented 5 years ago

:) seems like a good solution

MicroDroid commented 5 years ago

@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.

justice47 commented 5 years ago

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

justice47 commented 5 years ago

@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"
>
MicroDroid commented 5 years ago

Closed in #42