Skip to content

Commit

Permalink
Tweak styles and add sorting/filtering examples
Browse files Browse the repository at this point in the history
  • Loading branch information
DTCurrie committed Sep 10, 2024
1 parent 98c3e34 commit c526337
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 95 deletions.
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@
"@types/prismjs": "^1.26.3",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"@viamrobotics/eslint-config": "^0.3.0",
"@viamrobotics/prettier-config": "^0.3.4",
"@viamrobotics/eslint-config": "^0.6.1",
"@viamrobotics/prettier-config": "^0.3.5",
"@viamrobotics/typescript-config": "^0.1.0",
"autoprefixer": "^10.4.16",
"concurrently": "^8.2.2",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-sonarjs": "^0.23.0",
"eslint-plugin-sonarjs": "^1.0.4",
"eslint-plugin-svelte": "^2.35.1",
"eslint-plugin-tailwindcss": "^3.13.0",
"eslint-plugin-unicorn": "^49.0.0",
Expand Down
55 changes: 43 additions & 12 deletions packages/core/src/lib/table/ag-grid-table.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,68 @@
>
import {
createGrid,
type ColDef,
type ColGroupDef,
type GridApi,
type GridOptions,
type GridParams,
} from 'ag-grid-community';
import { onMount } from 'svelte';
import 'ag-grid-community/styles/ag-grid.css';
import 'ag-grid-community/styles/ag-theme-quartz.css';
import classNames from 'classnames';
import cx from 'classnames';
export let options: GridOptions<DataType> = {};
/** Defines the columns to render. */
export let columnDefs: (ColDef<DataType> | ColGroupDef<DataType>)[];
/** Defines the rows to be rendered. */
export let rowData: DataType[];
export let options: Omit<GridOptions<DataType>, 'columnDefs' | 'rowData'> = {};
export let params: GridParams = {};
/**
* A CSS rule to set the height for the table.
* @default "500px"
*/
export let height = '500px';
/** Additional CSS classes to pass to the table. */
let extraClasses: cx.Argument = '';
export { extraClasses as cx };
let grid: GridApi<DataType>;
let eGui: HTMLDivElement;
onMount(() => {
grid = createGrid(eGui, options, params);
$: grid?.updateGridOptions({ columnDefs });
$: grid?.updateGridOptions({ rowData });
$: grid?.updateGridOptions({ ...options });
return () => {
grid.destroy();
};
onMount(() => {
grid = createGrid(eGui, { ...options, columnDefs, rowData }, params);
return () => grid.destroy();
});
$: classes = classNames(
($$restProps.class as string | undefined) ?? '',
'ag-theme-quartz'
);
$: classes = cx('ag-theme-quartz rounded-none', extraClasses);
</script>

<div
bind:this={eGui}
{...$$restProps}
style="height: {height};"
class={classes}
{...$$restProps}
/>

<style>
.ag-theme-quartz {
/* disable all borders */
--ag-borders: none;
--ag-border-color: theme(borderColor.light);
--ag-font-family: theme(fontFamily.public-sans);
--ag-header-height: 30px;
--ag-header-foreground-color: theme(textColor.default);
--ag-header-background-color: transparent;
--ag-header-cell-hover-background-color: theme(backgroundColor.light);
--ag-header-cell-moving-background-color: theme(backgroundColor.light);
}
</style>
189 changes: 109 additions & 80 deletions packages/core/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -456,98 +456,127 @@ let hoverDelayMS = 1000;
const onHoverDelayMsInput = (event: Event) => {
hoverDelayMS = Number.parseInt((event.target as HTMLInputElement).value, 10);
};
let tableData = [
{
id: 1,
first_name: 'Bobette',
last_name: 'Dankov',
email: '[email protected]',
ip_address: '212.10.172.113',
},
{
id: 2,
first_name: 'Jack',
last_name: 'Biaggelli',
email: '[email protected]',
ip_address: '147.246.244.8',
},
{
id: 3,
first_name: 'Dalli',
last_name: 'Spain',
email: '[email protected]',
ip_address: '230.60.71.89',
},
{
id: 4,
first_name: 'Berte',
last_name: 'Simonard',
email: '[email protected]',
ip_address: '249.139.115.176',
},
{
id: 5,
first_name: 'Desirae',
last_name: 'Kondratyuk',
email: '[email protected]',
ip_address: '37.201.201.199',
},
{
id: 6,
first_name: 'Susannah',
last_name: 'Ilchuk',
email: '[email protected]',
ip_address: '129.106.9.65',
},
{
id: 7,
first_name: 'Koren',
last_name: 'Priditt',
email: '[email protected]',
ip_address: '133.252.171.244',
},
{
id: 8,
first_name: 'Silvano',
last_name: 'Dell Casa',
email: '[email protected]',
ip_address: '100.135.33.162',
},
{
id: 9,
first_name: 'Jens',
last_name: 'Darthe',
email: '[email protected]',
ip_address: '240.64.233.124',
},
{
id: 10,
first_name: 'Lynett',
last_name: 'Brakewell',
email: '[email protected]',
ip_address: '235.217.168.168',
},
];
const removeTableRow = () => {
const [_, ...data] = tableData;
tableData = [...data];
};
</script>

<NotificationContainer />

<div class="container mx-auto my-4 flex flex-col gap-8 p-4">
<AgGridTable
style="height: 500px"
columnDefs={[
{ field: 'id', headerName: 'ID' },
{
field: 'first_name',
headerName: 'First name',
unSortIcon: true,
comparator(valueA, valueB) {
return valueA > valueB ? 1 : -1;
},
},
{
field: 'last_name',
headerName: 'Last name',
unSortIcon: true,
comparator(valueA, valueB) {
return valueA > valueB ? 1 : -1;
},
},
{
field: 'email',
headerName: 'Email',
unSortIcon: true,
comparator(valueA, valueB) {
return valueA > valueB ? 1 : -1;
},
},
{ field: 'ip_address', headerName: 'IP address', filter: true },
]}
rowData={tableData}
options={{
defaultColDef: {
flex: 1,
},
columnDefs: [
{ field: 'id', headerName: 'ID' },
{ field: 'first_name', headerName: 'First name' },
{ field: 'last_name', headerName: 'Last name' },
{ field: 'email', headerName: 'Email' },
{ field: 'ip_address', headerName: 'IP address' },
],
rowData: [
{
id: 1,
first_name: 'Bobette',
last_name: 'Dankov',
email: '[email protected]',
ip_address: '212.10.172.113',
},
{
id: 2,
first_name: 'Jack',
last_name: 'Biaggelli',
email: '[email protected]',
ip_address: '147.246.244.8',
},
{
id: 3,
first_name: 'Dalli',
last_name: 'Spain',
email: '[email protected]',
ip_address: '230.60.71.89',
},
{
id: 4,
first_name: 'Berte',
last_name: 'Simonard',
email: '[email protected]',
ip_address: '249.139.115.176',
},
{
id: 5,
first_name: 'Desirae',
last_name: 'Kondratyuk',
email: '[email protected]',
ip_address: '37.201.201.199',
},
{
id: 6,
first_name: 'Susannah',
last_name: 'Ilchuk',
email: '[email protected]',
ip_address: '129.106.9.65',
},
{
id: 7,
first_name: 'Koren',
last_name: 'Priditt',
email: '[email protected]',
ip_address: '133.252.171.244',
},
{
id: 8,
first_name: 'Silvano',
last_name: 'Dell Casa',
email: '[email protected]',
ip_address: '100.135.33.162',
},
{
id: 9,
first_name: 'Jens',
last_name: 'Darthe',
email: '[email protected]',
ip_address: '240.64.233.124',
},
{
id: 10,
first_name: 'Lynett',
last_name: 'Brakewell',
email: '[email protected]',
ip_address: '235.217.168.168',
},
],
}}
/>

<Button on:click={removeTableRow}>Remove row</Button>
</div>

<div class="container mx-auto my-4 flex flex-col gap-8 p-4">
Expand Down

0 comments on commit c526337

Please sign in to comment.