Sortable Props
Pantanal Grid provides comprehensive sorting configuration through sortableProps, allowing fine-grained control over sorting behavior.
Single Mode with Allow Unsort
Default behavior: Clicking a sorted column cycles through ascending → descending → unsorted.
Multiple Mode with Indexes
Sort by multiple columns. The numbers show the sort priority order.
No Unsort Mode
When sortable-allow-unsort is false, clicking cycles between ascending and descending only.
Initial Sort Direction
The Date column has sortableInitialDirection: 'desc', so it starts descending when first clicked.
Basic Sortable Props
sortable-allow-unsort
Control whether users can remove sorting from columns.
Allow Unsort (Default)
<script setup lang="ts">
import { ref } from 'vue'
import { PantanalGrid, type ColumnDef, type SortDescriptor } from '@pantanal/grid'
const rows = ref([
{ id: 1, name: 'Product A', price: 99.99 },
{ id: 2, name: 'Product B', price: 49.99 },
{ id: 3, name: 'Product C', price: 19.99 }
])
const columns: ColumnDef[] = [
{ field: 'id', title: 'ID', width: 80, sortable: true },
{ field: 'name', title: 'Name', sortable: true },
{ field: 'price', title: 'Price', sortable: true }
]
const sort = ref<SortDescriptor[]>([])
</script>
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:sortable="true"
:sortable-allow-unsort="true"
v-model:sort="sort"
/>
</template>Disable Unsort
When sortable-allow-unsort is false, clicking a sorted column cycles between ascending and descending only:
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:sortable="true"
:sortable-allow-unsort="false"
v-model:sort="sort"
/>
</template>sortable-show-indexes
Display sort sequence indicators when using multiple column sorting.
With Indexes
<script setup lang="ts">
import { ref } from 'vue'
import { PantanalGrid, type ColumnDef, type SortDescriptor } from '@pantanal/grid'
const rows = ref([
{ id: 1, name: 'Product A', price: 99.99, category: 'Electronics', stock: 50 },
{ id: 2, name: 'Product B', price: 49.99, category: 'Clothing', stock: 100 },
{ id: 3, name: 'Product C', price: 19.99, category: 'Books', stock: 25 }
])
const columns: ColumnDef[] = [
{ field: 'id', title: 'ID', width: 80, sortable: true },
{ field: 'name', title: 'Name', sortable: true },
{ field: 'price', title: 'Price', sortable: true },
{ field: 'category', title: 'Category', sortable: true },
{ field: 'stock', title: 'Stock', sortable: true }
]
const sort = ref<SortDescriptor[]>([])
</script>
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:sortable="true"
sortable-mode="multiple"
:sortable-show-indexes="true"
v-model:sort="sort"
/>
</template>Without Indexes
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:sortable="true"
sortable-mode="multiple"
:sortable-show-indexes="false"
v-model:sort="sort"
/>
</template>sortable-initial-direction
Set the initial sort direction when a column is first clicked.
Initial Descending
<script setup lang="ts">
const columns: ColumnDef[] = [
{ field: 'id', title: 'ID', width: 80, sortable: true },
{ field: 'name', title: 'Name', sortable: true },
{ field: 'price', title: 'Price', sortable: true },
{
field: 'date',
title: 'Date',
sortable: true,
sortableInitialDirection: 'desc' // Column-level override
}
]
</script>
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:sortable="true"
sortable-initial-direction="asc"
v-model:sort="sort"
/>
</template>Global Initial Direction
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:sortable="true"
sortable-initial-direction="desc"
v-model:sort="sort"
/>
</template>sortable-mode
Choose between single or multiple column sorting.
Single Mode (Default)
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:sortable="true"
sortable-mode="single"
v-model:sort="sort"
/>
</template>Multiple Mode
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:sortable="true"
sortable-mode="multiple"
:sortable-show-indexes="true"
v-model:sort="sort"
/>
</template>Complete Example
Combining all sortable props:
<script setup lang="ts">
import { ref } from 'vue'
import { PantanalGrid, type ColumnDef, type SortDescriptor } from '@pantanal/grid'
const rows = ref([
{ id: 1, name: 'Product A', price: 99.99, category: 'Electronics', date: '2024-01-15', stock: 50 },
{ id: 2, name: 'Product B', price: 49.99, category: 'Clothing', date: '2024-02-20', stock: 100 },
{ id: 3, name: 'Product C', price: 19.99, category: 'Books', date: '2024-03-10', stock: 25 },
{ id: 4, name: 'Product D', price: 79.99, category: 'Electronics', date: '2024-01-05', stock: 75 }
])
const columns: ColumnDef[] = [
{ field: 'id', title: 'ID', width: 80, sortable: true },
{ field: 'name', title: 'Name', sortable: true },
{ field: 'price', title: 'Price', sortable: true },
{ field: 'category', title: 'Category', sortable: true },
{
field: 'date',
title: 'Date',
sortable: true,
sortableInitialDirection: 'desc' // Newest first
},
{ field: 'stock', title: 'Stock', sortable: true }
]
const sort = ref<SortDescriptor[]>([])
</script>
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:sortable="true"
sortable-mode="multiple"
:sortable-allow-unsort="true"
:sortable-show-indexes="true"
sortable-initial-direction="asc"
v-model:sort="sort"
/>
</template>Column-Level Overrides
Override sortable props per column:
<script setup lang="ts">
const columns: ColumnDef[] = [
{
field: 'name',
title: 'Name',
sortable: true,
sortableAllowUnsort: false, // Cannot unsort this column
sortableInitialDirection: 'asc'
},
{
field: 'price',
title: 'Price',
sortable: true,
sortableInitialDirection: 'desc' // Starts descending
},
{
field: 'date',
title: 'Date',
sortable: true,
sortableInitialDirection: 'desc' // Newest first
}
]
</script>Use Cases
Simple Data Table
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:sortable="true"
sortable-mode="single"
:sortable-allow-unsort="true"
/>
</template>Always Sorted Table
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:sortable="true"
sortable-mode="single"
:sortable-allow-unsort="false"
/>
</template>Multi-Column Analysis
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:sortable="true"
sortable-mode="multiple"
:sortable-show-indexes="true"
:sortable-allow-unsort="true"
/>
</template>Server-Side Sorting
All sortable props work with server-side sorting:
<script setup lang="ts">
import { ref, watchEffect } from 'vue'
import { PantanalGrid, type ColumnDef, type SortDescriptor } from '@pantanal/grid'
const rows = ref([])
const sort = ref<SortDescriptor[]>([])
watchEffect(async () => {
const params = new URLSearchParams()
// Send all sorts to server
sort.value.forEach((s, index) => {
params.append(`sort[${index}][field]`, s.field)
params.append(`sort[${index}][dir]`, s.dir)
})
const response = await fetch(`/api/data?${params}`)
const data = await response.json()
rows.value = data.items
})
</script>
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:sortable="true"
sortable-mode="multiple"
:sortable-show-indexes="true"
:server-side="true"
v-model:sort="sort"
/>
</template>See Also
- SortableProps API - Complete API reference
- Sorting Guide - Sorting documentation
- Sorting Examples - More sorting examples