Features
Grouping
Learn how to set up and configure grouping in your GridCraft data grid table. Allow better organization and structure of your data for better data analysis and visualization in your SvelteKit applications.
How to Use Grouping
Adding grouping to your data table is very simple. We only need to set the groupby
property on our <Grid>
component:
+page.svelte
<Grid
bind:data={clients}
...
groupby={columnKey} />
The groupby
value needs to be a key of one of the defined columns. In the following example status
:
+page.svelte
<script>
interface Client {
...
status: Date;
}
let columnKey = "status";
</script>
<Grid
bind:data={clients}
...
bind:groupby={columnKey} />
Name | Age | ||||
---|---|---|---|---|---|
Active 3 / 3 | |||||
Abraham Baker Abraham.Baker@gmail.com | 42 | ||||
Adem Lane Adem.Lane@icloud.com | 73 | ||||
Alec Whitten AW_41@yahoo.com | 67 | ||||
Inactive 1 / 1 | |||||
Adriana O'Sullivan Adriana.OSullivan@protonmail.com | 26 | ||||
Pending 1 / 1 | |||||
Adil Floyd Adil.Floyd@icloud.com | 72 |
of 5 Results
Page 1 of 1
Group headers are collapsable/expandable. By default all group headers are expanded. If we want them to be collapsed by default we can can set the property groupsExpandedDefault
to false
.
+page.svelte
<Grid
bind:data={clients}
...
groupsExpandedDefault={false}
groupby={columnKey} />
Full Example
<script>
interface Client {
id: string;
firstname: string;
lastname: string;
age: number;
}
export let data: PageData;
let clients: Client[] = data.clients;
let groupBy = "";
let columns: GridColumn<Client>[] = [
{
key: 'firstname',
title: 'First Name',
},
{
key: 'lastname',
title: 'First Name',
},
{
key: 'age',
title: 'Age'
}
];
</script>
<!-- this select box is just for demonstration purposes -->
<select bind:value={groupBy} >
<option value="">Select Group By Column</option>
{#each columns as col (col.key)}
<option value={col.key}>{col.title}</option>
{/each}
</select>
<Grid
bind:data={clients}
bind:columns
bind:groupby />