Data exporting

Published at Oct 15, 2024

Product name
Price
Quantity
Category
Expiration date
Sprouts - Onion
261.51
972
furniture
7/14/2023
Beer - True North Lager
191.32
38
furniture
7/17/2023
Milk - Condensed
826.1
714
furniture
6/9/2022
Brandy Cherry - Mcguinness
555.07
212
electronics
2/26/2022
Olive - Spread Tapenade
506.45
509
furniture
3/5/2022
Tea - Black Currant
750.65
848
clothing
11/1/2022
Coconut Milk - Unsweetened
658.56
149
electronics
8/5/2022
Nut - Walnut, Pieces
763.42
147
furniture
9/7/2023
Apple - Northern Spy
81.35
950
clothing
12/12/2023
Orange - Canned, Mandarin
939.59
200
furniture
7/28/2022
Veal - Brisket, Provimi,bnls
353.49
226
electronics
6/17/2023
Wine - Ice Wine
867.85
618
clothing
5/10/2022
Table Cloth 54x72 White
703.86
770
furniture
12/9/2023
Wine - Cotes Du Rhone Parallele
967.56
435
clothing
8/25/2022
Wine - Duboeuf Beaujolais
247.42
105
clothing
7/23/2022
Carrots - Jumbo
880.11
350
furniture
3/21/2022
Wine - Touraine Azay - Le - Rideau
949.68
290
electronics
12/30/2023
Schnappes Peppermint - Walker
879.93
69
clothing
12/19/2023
Wine - Champagne Brut Veuve
496.79
201
clothing
2/21/2023
Appetizer - Smoked Salmon / Dill
274.6
856
electronics
1/1/2022
0 : 20 of 1000

Implementation

Work in progress. See the code below.

Code

Column definitions

import type { BaseColumn } from "$lib/datagrid/types";
import type { InventoryDataRow } from "$lib/data/inventory";

export const columns = [
    {
        id: 'checkbox',
        title: 'Row selection',
        width: '50px',
        pinned: {
            position: 'left'
        },
        visible: true,
        resizable: false,
        sortable: false,
        exportable: false,
        selectable: false,
        moveable: false
    },
    {
        id: 'product.name',
        title: 'Product name',
        sortable: true,
        grow: true,
        filterType: 'string',
        filterValue: '',
    },
    {
        id: 'price',
        title: 'Price',
        sortable: true,
        filterType: 'range',
        filterValue: [-99999999999, 9999999999],
        align: 'end',
    },
    {
        id: 'quantity',
        title: 'Quantity',
        sortable: true,
        filterType: 'number',
        filterValue: '',
        align: 'end',

    },
    {
        id: 'category',
        title: 'Category',
        filterType: 'select',
        filterValue: '',
        options: [
            { label: 'Everything', value: '' },
            { label: 'Furniture', value: 'furniture' },
            { label: 'Clothing', value: 'clothing' },
            { label: 'Electronics', value: 'electronics' }
        ],
    },
    {
        id: 'expiration_date',
        title: 'Expiration date',
        filterType: 'date',
        filterValue: '',
    },
] satisfies BaseColumn<InventoryDataRow>[]

Datagrid component

<script lang="ts">
	import { setContext } from 'svelte';
	import { columns } from './columns.svelte';
	import { inventoryData as data } from '$lib/data/inventory';
	import { TzezarDatagrid } from '$lib/datagrid/tzezar-datagrid.svelte';
	import * as Datagrid from '$lib/datagrid';

	let datagrid = setContext(
		`datagrid`,
		new TzezarDatagrid({
			data,
			columns,
			options: {
				topbar: {
					display: true,
					displayCopyDataMenu: true
				}
			}
		})
	);
</script>

<Datagrid.Datagrid>
	{#snippet head()}
		{#each datagrid.columns as column, i (column.id)}
			{#if column.id === 'checkbox'}
				<Datagrid.HeaderWithoutSpacing {column} title={column.title}>
					<Datagrid.HeaderRowSelectionDropdown />
				</Datagrid.HeaderWithoutSpacing>
			{:else}
				<Datagrid.Header {column} />
			{/if}
		{/each}
	{/snippet}
	{#snippet body()}
		{#each datagrid.state.processedData as row, rowIndex}
			<Datagrid.Row rowId={row.id} {rowIndex}>
				{#each datagrid.columns as column, columnIndex}
					{@const props = { row, rowIndex, column, columnIndex }}
					{#if column.id === 'checkbox'}
						<Datagrid.CellWithoutSpacing {...props}>
							<Datagrid.CellRowSelectionCheckbox {row} />
						</Datagrid.CellWithoutSpacing>
					{:else if column.id === 'product.name'}
						<Datagrid.Cell
							class={{ data: 'overflow-hidden text-ellipsis text-nowrap' }}
							{...props}
						/>
					{:else}
						<Datagrid.Cell {...props} />
					{/if}
				{/each}
			</Datagrid.Row>
		{/each}
	{/snippet}
</Datagrid.Datagrid>
In the coming days, the grid will officially launch its version 1.0. I recommend waiting until the release before incorporating it into your projects, as we've completely rewritten and simplified the internal logic, making it more efficient. Version 1.0 will also introduce exciting new features such as row grouping and aggregation. If you have any questions or feedback, feel free to reach out! If you find this project valuable, please consider giving it a star on GitHub. Thank you for your support! ❤️