Filtering
Pantanal Grid provides powerful filtering capabilities with multiple operators, filter modes, and custom filter UIs.
Basic Filtering
Filtering is enabled by default on all columns. The filter row is shown automatically. Disable it globally with :filterable="false" or per column with filterable: false:
vue
<script setup lang="ts">
import { ref } from 'vue'
import { PantanalGrid, type ColumnDef, type FilterDescriptor } from '@pantanal/grid'
const rows = ref([/* ... */])
const columns: ColumnDef[] = [
{ field: 'name', title: 'Name' },
{ field: 'price', title: 'Price' }
]
const filter = ref<FilterDescriptor[]>([])
</script>
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
v-model:filter="filter"
/>
</template>Filter Modes
Filter Row Mode
Display filter inputs directly in the header row:
vue
<script setup lang="ts">
const columns: ColumnDef[] = [
{
field: 'name',
title: 'Name',
filterable: true,
filterableMode: 'row'
}
]
</script>Filter Menu Mode
Use a dropdown menu for filtering:
vue
<script setup lang="ts">
const columns: ColumnDef[] = [
{
field: 'name',
title: 'Name',
filterable: true,
filterableMode: 'menu'
}
]
</script>Filter Operators
Available operators:
contains- Contains text (default for strings)eq- Equalsneq- Not equalsgt- Greater thangte- Greater than or equallt- Less thanlte- Less than or equalstartswith- Starts withendswith- Ends withisnull- Is nullisnotnull- Is not nullisempty- Is emptyisnotempty- Is not empty
Filter UI Types
Textbox (Default)
vue
<script setup lang="ts">
const columns: ColumnDef[] = [
{
field: 'name',
title: 'Name',
filterable: true,
filterableUI: 'textbox'
}
]
</script>Numeric
vue
<script setup lang="ts">
const columns: ColumnDef[] = [
{
field: 'price',
title: 'Price',
filterable: true,
filterableUI: 'numeric'
}
]
</script>Date
vue
<script setup lang="ts">
const columns: ColumnDef[] = [
{
field: 'createdAt',
title: 'Created At',
filterable: true,
filterableUI: 'date'
}
]
</script>Boolean
vue
<script setup lang="ts">
const columns: ColumnDef[] = [
{
field: 'active',
title: 'Active',
filterable: true,
filterableUI: 'boolean'
}
]
</script>Dropdown
vue
<script setup lang="ts">
const columns: ColumnDef[] = [
{
field: 'category',
title: 'Category',
filterable: true,
filterableUI: 'dropdown',
filterableOptions: [
{ value: 'Electronics', label: 'Electronics' },
{ value: 'Clothing', label: 'Clothing' },
{ value: 'Accessories', label: 'Accessories' }
]
}
]
</script>Multiple Filters
Enable multiple filter criteria for a column:
vue
<script setup lang="ts">
const columns: ColumnDef[] = [
{
field: 'price',
title: 'Price',
filterable: true,
filterableMulti: true,
filterableExtra: true // Allow second filter criterion
}
]
</script>Custom Filter Operator
Set default filter operator:
vue
<script setup lang="ts">
const columns: ColumnDef[] = [
{
field: 'name',
title: 'Name',
filterable: true,
filterableOperator: 'startswith'
}
]
</script>Filter Events
Listen to filter changes:
vue
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
@update:filter="handleFilterChange"
/>
</template>
<script setup lang="ts">
import type { FilterDescriptor } from '@pantanal/grid'
function handleFilterChange(newFilter: FilterDescriptor[]) {
console.log('Filter changed:', newFilter)
// Update server-side data, etc.
}
</script>Server-Side Filtering
For server-side filtering, handle the filter change event:
vue
<script setup lang="ts">
import { ref } from 'vue'
import { PantanalGrid, type FilterDescriptor } from '@pantanal/grid'
const rows = ref([/* ... */])
const filter = ref<FilterDescriptor[]>([])
async function handleFilterChange(newFilter: FilterDescriptor[]) {
filter.value = newFilter
// Fetch filtered data from server
const response = await fetch(`/api/data?filter=${JSON.stringify(newFilter)}`)
rows.value = await response.json()
}
</script>
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:server-side="true"
v-model:filter="filter"
@update:filter="handleFilterChange"
/>
</template>Case-Insensitive Filtering
Enable case-insensitive filtering:
vue
<script setup lang="ts">
const columns: ColumnDef[] = [
{
field: 'name',
title: 'Name',
filterable: true,
filterableIgnoreCase: true
}
]
</script>Tips
- Use
filterableMode: 'row'for quick filtering - Use
filterableMode: 'menu'for advanced filtering with multiple operators - Provide
filterableOptionsfor dropdown filters to improve UX - For server-side filtering, always handle the
update:filterevent - Use
filterableMulti: truefor complex filtering scenarios