mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-20 20:33:02 +00:00
docs(data-table): add filterable examples
This commit is contained in:
parent
2ac021ffc7
commit
be000afdbd
3 changed files with 117 additions and 0 deletions
|
@ -460,6 +460,22 @@ title="Load balancers" description="Your organization's active load balancers."
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</DataTable>
|
</DataTable>
|
||||||
|
|
||||||
|
### Filterable
|
||||||
|
|
||||||
|
By default, `ToolbarSearch` will not filter `DataTable` rows.
|
||||||
|
|
||||||
|
Set `shouldFilterRows` to `true` to enable client-side filtering. The default filtering performs a basic string comparison on cell values that are of a string or a number type.
|
||||||
|
|
||||||
|
Note that in-memory filtering is not optimal for large data sets, where you might consider using server-side search.
|
||||||
|
|
||||||
|
<FileSource src="/framed/DataTable/DataTableFilterable" />
|
||||||
|
|
||||||
|
### Filterable (custom)
|
||||||
|
|
||||||
|
`shouldFilterRows` also accepts a function and passes it the current row and value. It expects the function to return a boolean.
|
||||||
|
|
||||||
|
<FileSource src="/framed/DataTable/DataTableFilterCustom" />
|
||||||
|
|
||||||
### Zebra stripes
|
### Zebra stripes
|
||||||
|
|
||||||
<DataTable zebra
|
<DataTable zebra
|
||||||
|
|
55
docs/src/pages/framed/DataTable/DataTableFilterCustom.svelte
Normal file
55
docs/src/pages/framed/DataTable/DataTableFilterCustom.svelte
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<script>
|
||||||
|
import {
|
||||||
|
DataTable,
|
||||||
|
Toolbar,
|
||||||
|
ToolbarContent,
|
||||||
|
ToolbarSearch,
|
||||||
|
ToolbarMenu,
|
||||||
|
ToolbarMenuItem,
|
||||||
|
Button,
|
||||||
|
} from "carbon-components-svelte";
|
||||||
|
|
||||||
|
let rows = Array.from({ length: 10 }).map((_, i) => ({
|
||||||
|
id: i,
|
||||||
|
name: "Load Balancer " + (i + 1),
|
||||||
|
protocol: "HTTP",
|
||||||
|
port: 3000 + i * 10,
|
||||||
|
rule: i % 2 ? "Round robin" : "DNS delegation",
|
||||||
|
}));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DataTable
|
||||||
|
sortable
|
||||||
|
title="Load balancers"
|
||||||
|
description="Your organization's active load balancers."
|
||||||
|
headers="{[
|
||||||
|
{ key: 'name', value: 'Name' },
|
||||||
|
{ key: 'protocol', value: 'Protocol' },
|
||||||
|
{ key: 'port', value: 'Port' },
|
||||||
|
{ key: 'rule', value: 'Rule' },
|
||||||
|
]}"
|
||||||
|
rows="{rows}"
|
||||||
|
>
|
||||||
|
<Toolbar>
|
||||||
|
<ToolbarContent>
|
||||||
|
<ToolbarSearch
|
||||||
|
persistent
|
||||||
|
value="round"
|
||||||
|
shouldFilterRows="{(row, value) => {
|
||||||
|
return (
|
||||||
|
/(6|8)$/.test(row.name) &&
|
||||||
|
row.rule.toLowerCase().includes(value.toLowerCase())
|
||||||
|
);
|
||||||
|
}}"
|
||||||
|
/>
|
||||||
|
<ToolbarMenu>
|
||||||
|
<ToolbarMenuItem primaryFocus>Restart all</ToolbarMenuItem>
|
||||||
|
<ToolbarMenuItem href="https://cloud.ibm.com/docs/loadbalancer-service">
|
||||||
|
API documentation
|
||||||
|
</ToolbarMenuItem>
|
||||||
|
<ToolbarMenuItem hasDivider danger>Stop all</ToolbarMenuItem>
|
||||||
|
</ToolbarMenu>
|
||||||
|
<Button>Create balancer</Button>
|
||||||
|
</ToolbarContent>
|
||||||
|
</Toolbar>
|
||||||
|
</DataTable>
|
46
docs/src/pages/framed/DataTable/DataTableFilterable.svelte
Normal file
46
docs/src/pages/framed/DataTable/DataTableFilterable.svelte
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<script>
|
||||||
|
import {
|
||||||
|
DataTable,
|
||||||
|
Toolbar,
|
||||||
|
ToolbarContent,
|
||||||
|
ToolbarSearch,
|
||||||
|
ToolbarMenu,
|
||||||
|
ToolbarMenuItem,
|
||||||
|
Button,
|
||||||
|
} from "carbon-components-svelte";
|
||||||
|
|
||||||
|
let rows = Array.from({ length: 10 }).map((_, i) => ({
|
||||||
|
id: i,
|
||||||
|
name: "Load Balancer " + (i + 1),
|
||||||
|
protocol: "HTTP",
|
||||||
|
port: 3000 + i * 10,
|
||||||
|
rule: i % 2 ? "Round robin" : "DNS delegation",
|
||||||
|
}));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DataTable
|
||||||
|
sortable
|
||||||
|
title="Load balancers"
|
||||||
|
description="Your organization's active load balancers."
|
||||||
|
headers="{[
|
||||||
|
{ key: 'name', value: 'Name' },
|
||||||
|
{ key: 'protocol', value: 'Protocol' },
|
||||||
|
{ key: 'port', value: 'Port' },
|
||||||
|
{ key: 'rule', value: 'Rule' },
|
||||||
|
]}"
|
||||||
|
rows="{rows}"
|
||||||
|
>
|
||||||
|
<Toolbar>
|
||||||
|
<ToolbarContent>
|
||||||
|
<ToolbarSearch persistent value="round" shouldFilterRows />
|
||||||
|
<ToolbarMenu>
|
||||||
|
<ToolbarMenuItem primaryFocus>Restart all</ToolbarMenuItem>
|
||||||
|
<ToolbarMenuItem href="https://cloud.ibm.com/docs/loadbalancer-service">
|
||||||
|
API documentation
|
||||||
|
</ToolbarMenuItem>
|
||||||
|
<ToolbarMenuItem hasDivider danger>Stop all</ToolbarMenuItem>
|
||||||
|
</ToolbarMenu>
|
||||||
|
<Button>Create balancer</Button>
|
||||||
|
</ToolbarContent>
|
||||||
|
</Toolbar>
|
||||||
|
</DataTable>
|
Loading…
Add table
Add a link
Reference in a new issue