VueJs - Tri des donnée

Par arnich, il y a 10 ans


Bonjour,

J'utilise vueJs (j'aime me faire du mal).
J'essais de trier les données lors du click sur la colone dans le head de mon tableau

Voici mon code :

<table class="datatables"> <thead> <tr> <th><a @click="orderKey = 'libelle'">Legende</a></th> <th><a @click="orderKey = 'description'">Description</a></th> </tr> </thead> <tbody> <tr v-for="carte in cartes | orderBy 'libelle' order"> <td> <a v-link="{ name: 'cartes.show', params: {id: 1}}">{{ carte.libelle }}</a> </td> <td>{{ carte.description }}</td> </tr> </tbody> </table>

Je pensais avoir respecté ce qui est dit dans la doc (http://vuejs.org/api/#orderBy)

Si quelqu'un peut me mettre sur la piste je lui en serais grandement reconnaissant.

1 réponse

arnich, il y a 10 ans

Bonjour,

Mon problème est resolu. Dans mon v-for j'avias codé le order en dur.
Il faut remplacer

<tr v-for="carte in cartes | orderBy 'libelle' order">

par

<tr v-for="carte in cartes | orderBy orderKey order">