Components
Smart Search
Smart Search provides advanced filtering and search capabilities for tables. It supports multiple field types, operators, and dynamic column definitions.
Overview
Smart Search is integrated into PageLayoutTemplate and provides:
- Text search with multiple operators
- Date range filtering
- Select dropdowns with options
- Complex filter combinations
- Persistent filter state
Column Definitions
Smart Search columns are defined as hooks to support dynamic definitions:
// hooks/smart-search-columns.ts
import type { Column } from '@wayvo-ai/core/ui/smart-search';
import type { Entity } from '@/lib/common/ds/types/module/Entity';
export default function useSmartSearchColumns(): Column<Entity>[] {
return [
{
key: 'name',
label: 'Name',
type: 'Text',
defaultOperator: 'is',
},
{
key: 'description',
label: 'Description',
type: 'Text',
defaultOperator: 'contains',
},
{
key: 'status',
label: 'Status',
type: 'Select',
defaultOperator: 'is',
options: [
{ value: 'draft', label: 'Draft' },
{ value: 'active', label: 'Active' },
{ value: 'completed', label: 'Completed' },
],
getOptionLabel: (opt) => opt.label,
getOptionValue: (opt) => opt.value,
},
{
key: 'createdAt',
label: 'Created At',
type: 'Date',
defaultOperator: 'on',
},
];
}
Column Types
Text
{
key: 'name',
label: 'Name',
type: 'Text',
defaultOperator: 'is', // or 'contains', 'startsWith', 'endsWith'
}
Date
{
key: 'createdAt',
label: 'Created At',
type: 'Date',
defaultOperator: 'on', // or 'before', 'after', 'between'
}
Select (Fixed Options)
{
key: 'status',
label: 'Status',
type: 'Select',
defaultOperator: 'is',
options: [
{ value: 'draft', label: 'Draft' },
{ value: 'active', label: 'Active' },
],
getOptionLabel: (opt) => opt.label,
getOptionValue: (opt) => opt.value,
}
Select (Dynamic Options from Store)
For master data like customers or users:
// hooks/use-customer-options.ts
export function useCustomerOptions() {
const store = useStore<Customer>({
datasourceId: 'Customers',
page: 'page-name',
alias: 'customer-options',
limit: 1000,
autoQuery: true,
select: ['customerId', 'customerName'],
sort: { customerName: 1 },
});
return { rows: useDBRows(store), isLoading: useIsStoreLoading(store) };
}
// In smart-search-columns.ts
const { rows: customerOptions } = useCustomerOptions();
{
key: 'customerId',
label: 'Customer',
type: 'Select',
defaultOperator: 'is',
options: customerOptions,
getOptionLabel: (option) => option.customerName,
getOptionValue: (option) => option.customerId,
}
Operators
Text Operators
is- Exact matchcontains- Contains substringstartsWith- Starts withendsWith- Ends withisNot- Not equal
Date Operators
on- On specific datebefore- Before dateafter- After datebetween- Date range
Select Operators
is- Equal toisNot- Not equal toin- In list (multiple selection)
Usage with PageLayoutTemplate
import { PageLayoutTemplate } from '@wayvo-ai/core/ui';
import useSmartSearchColumns from './hooks/smart-search-columns';
export default function PageContent() {
const store = useEntityStore();
const smartSearchColumns = useSmartSearchColumns();
return (
<PageLayoutTemplate
store={store}
smartSearchColumns={smartSearchColumns}
// ... other props
/>
);
}
Best Practices
- Use hooks for dynamic columns - Support role-based or context-based columns
- Share options hooks - Use the same options hook for SmartSearch and ComboboxInput
- Limit options for Select - Use
selectto only fetch needed fields - Sort options alphabetically - Better UX for users