V
V
Vyacheslav2019-09-23 23:38:26
Vue.js
Vyacheslav, 2019-09-23 23:38:26

How to track descending/ascending sort state in vue js?

Please tell me how to properly track the sort state, i.e. with each subsequent click on th, the data was sorted in reverse order, the code:

<tempate>
<table>
...
<th @click="sorted({ sortedBy: 'id', type: 'integer'}, $event)">Id</th>
<th @click="sorted({ sortedBy: 'title', type: 'string'}, $event)">title</th>
<th @click="sorted({ sortedBy: 'name', type: 'string'}, $event)">name</th>
...
</table>
</tempate>

<script>
...
data: {
    list: [
        {id, title, name},
        ...
    ]
},
methods: {
    sorted({sortedBy, type}, e) {
    }
}
...
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-09-23
@lmnsky84

Add a boolean property to the component that will indicate the sort order, and toggle its value when calling the sorted method. For example .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question