Skip to content

Commit

Permalink
docs(table): add additional custom sort details (nuxt#2234)
Browse files Browse the repository at this point in the history
  • Loading branch information
L422Y authored and patrick-hofmann committed Oct 3, 2024
1 parent 824e2b8 commit 3d1fd63
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion docs/content/2.components/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ Use the `columns` prop to configure which columns to display. It's an array of o
- `direction` - The sort direction to use on first click. Defaults to `asc`.
- `class` - The class to apply to the column cells.
- `rowClass` - The class to apply to the data column cells. :u-badge{label="New" class="!rounded-full" variant="subtle"}
- `sort` - Pass your own `sort` function. Defaults to a simple _greater than_ / _less than_ comparison.
- `sort` - Pass your own `sort` function. Defaults to a simple _greater than_ / _less than_ comparison.

Arguments for the `sort` function are: Value A, Value B, Direction - 'asc' or 'desc'

Example `sort` function:
```
(a, b, direction) => {
if (!a || !b) return 0
const aPrice = parseInt(a.replace(/[,$]/g, ""))
const bPrice = parseInt(b.replace(/[,$]/g, ""))
return direction === "asc" ? aPrice - bPrice : bPrice - aPrice
}
```

::component-example{class="grid"}
---
Expand Down

0 comments on commit 3d1fd63

Please sign in to comment.