@emamid/svelte-data-table 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -0
- package/dist/DataTable.doc.d.ts +7 -0
- package/dist/DataTable.doc.js +7 -0
- package/dist/DataTable.svelte +13 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
## Svelte Data Table based on [Flowbite Svelte](https://flowbite-svelte.com/), [Flowbite Icons](https://flowbite.com/icons/), and [Tailwind](https://tailwindcss.com/)
|
|
2
|
+
|
|
3
|
+
This data table is designed for viewing and editing data in an array of objects. It's built using the Flowbite Svelte library's Table components and works in conjunction with it, with support for custom cell editors, moving focus between cells with tab and enter, column sorting (simple and custom), conditional CSS, and more.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
To add to an existing Svelte app, first install Tailwind if you haven't already:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
> npx svelte-add@latest tailwindcss
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then install the Flowbite components and icons along with the data table component.
|
|
14
|
+
```bash
|
|
15
|
+
> npm i flowbite-svelte flowbite flowbite-svelte-icons @emamid/svelte-data-table
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Basic example
|
|
19
|
+
|
|
20
|
+
```html
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
import DataTable from '@emamid/svelte-data-table';
|
|
23
|
+
import type { ColumnConfig } from '@emamid/svelte-data-table';
|
|
24
|
+
|
|
25
|
+
const columns: ColumnConfig[] = [
|
|
26
|
+
{ canSort: true, key: 'firstName', title: 'First Name' },
|
|
27
|
+
{ canSort: true, key: 'lastName', title: 'Last Name' },
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const items: any[] = [
|
|
31
|
+
{ firstName: 'Bilbo', lastName: 'Baggins'},
|
|
32
|
+
{ firstName: 'Frodo', lastName: 'Baggins'},
|
|
33
|
+
{ firstName: 'Samwise', lastName: 'Gamgee'},
|
|
34
|
+
{ firstName: 'Meriadoc', lastName: 'Brandybuck'},
|
|
35
|
+
{ firstName: 'Peregrin', lastName: 'Took'},
|
|
36
|
+
];
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<main>
|
|
40
|
+
<DataTable
|
|
41
|
+
{columns}
|
|
42
|
+
{items}
|
|
43
|
+
/>
|
|
44
|
+
</main>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Examples for most of the component's features are under /examples . You can find the documentation [here](https://emamid.github.io/svelte-data-table/).
|
|
48
|
+
|
|
49
|
+
#### Example 1 - Basic data table
|
|
50
|
+

|
|
51
|
+
|
|
52
|
+
#### Example 2 - Table with cell focus components
|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
#### Example 3 - Table with cell focus Select components, cell renderers, and custom sort
|
|
56
|
+

|
|
57
|
+
|
|
58
|
+
#### Example 4 - Table with actions and cell view components
|
|
59
|
+

|
|
60
|
+
|
|
61
|
+
#### Example 5 - Table with custom cell component
|
|
62
|
+

|
|
63
|
+
|
|
64
|
+
#### Example 6 - Table with cell and row class getter functions
|
|
65
|
+

|
package/dist/DataTable.doc.d.ts
CHANGED
|
@@ -26,6 +26,13 @@
|
|
|
26
26
|
* @property {string} [trClassAppend] - Classes to be appended to TableBodyRow.class . trClassGetter can further modify this.
|
|
27
27
|
* @property {string} [trClassOverride] - Classes to replace TableBodyRow.class with. trClassGetter can further modify this.
|
|
28
28
|
* @property {RowClassFunction} [trClassGetter] - Calculates the CSS classes for a TableBodyRow .
|
|
29
|
+
* @property {boolean} [striped] - Passes through to on {@link https://flowbite-svelte.com/docs/components/table}
|
|
30
|
+
* @property {boolean} [hoverable] - Passes through to on {@link https://flowbite-svelte.com/docs/components/table}
|
|
31
|
+
* @property {boolean} [noborder] - Passes through to on {@link https://flowbite-svelte.com/docs/components/table}
|
|
32
|
+
* @property {boolean} [shadow] - Passes through to on {@link https://flowbite-svelte.com/docs/components/table}
|
|
33
|
+
* @property {string} [color] - Passes through to on {@link https://flowbite-svelte.com/docs/components/table}
|
|
34
|
+
* @property {string} [customColor] - Passes through to on {@link https://flowbite-svelte.com/docs/components/table}
|
|
35
|
+
|
|
29
36
|
* @fires action
|
|
30
37
|
* @fires cellChanged
|
|
31
38
|
* @fires cellClicked
|
package/dist/DataTable.doc.js
CHANGED
|
@@ -27,6 +27,13 @@
|
|
|
27
27
|
* @property {string} [trClassAppend] - Classes to be appended to TableBodyRow.class . trClassGetter can further modify this.
|
|
28
28
|
* @property {string} [trClassOverride] - Classes to replace TableBodyRow.class with. trClassGetter can further modify this.
|
|
29
29
|
* @property {RowClassFunction} [trClassGetter] - Calculates the CSS classes for a TableBodyRow .
|
|
30
|
+
* @property {boolean} [striped] - Passes through to on {@link https://flowbite-svelte.com/docs/components/table}
|
|
31
|
+
* @property {boolean} [hoverable] - Passes through to on {@link https://flowbite-svelte.com/docs/components/table}
|
|
32
|
+
* @property {boolean} [noborder] - Passes through to on {@link https://flowbite-svelte.com/docs/components/table}
|
|
33
|
+
* @property {boolean} [shadow] - Passes through to on {@link https://flowbite-svelte.com/docs/components/table}
|
|
34
|
+
* @property {string} [color] - Passes through to on {@link https://flowbite-svelte.com/docs/components/table}
|
|
35
|
+
* @property {string} [customColor] - Passes through to on {@link https://flowbite-svelte.com/docs/components/table}
|
|
36
|
+
|
|
30
37
|
* @fires action
|
|
31
38
|
* @fires cellChanged
|
|
32
39
|
* @fires cellClicked
|
package/dist/DataTable.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>import { createEventDispatcher } from "svelte";
|
|
2
|
-
import { Table, TableBody, TableBodyRow, TableHead } from "flowbite-svelte";
|
|
2
|
+
import { P, Table, TableBody, TableBodyRow, TableHead } from "flowbite-svelte";
|
|
3
3
|
import DataTableDataCell from "./DataTableDataCell.svelte";
|
|
4
4
|
import DataTableHeaderCell from "./DataTableHeaderCell.svelte";
|
|
5
5
|
import { joinClasses } from "./common.js";
|
|
@@ -46,14 +46,23 @@ let sortedItems = [];
|
|
|
46
46
|
let focusedColumnKeyID = null;
|
|
47
47
|
let focusedItemKey = null;
|
|
48
48
|
const sortBySortKey = (a, b) => {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
let aValue = a[sortKey];
|
|
50
|
+
let bValue = b[sortKey];
|
|
51
|
+
if (aValue === bValue) {
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
51
54
|
if (typeof aValue === "string" && typeof bValue === "string") {
|
|
52
55
|
return aValue.localeCompare(bValue);
|
|
53
56
|
}
|
|
54
|
-
if (
|
|
57
|
+
if (typeof aValue === "number" && typeof bValue === "number") {
|
|
55
58
|
return aValue - bValue;
|
|
56
59
|
}
|
|
60
|
+
if (typeof aValue === "number" || typeof bValue === "number") {
|
|
61
|
+
return (aValue || 0) - (bValue || 0);
|
|
62
|
+
}
|
|
63
|
+
if (typeof aValue === "string" || typeof bValue === "string") {
|
|
64
|
+
return (aValue || "").localeCompare(bValue || "");
|
|
65
|
+
}
|
|
57
66
|
return JSON.stringify(aValue).localeCompare(JSON.stringify(bValue));
|
|
58
67
|
};
|
|
59
68
|
$: {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emamid/svelte-data-table",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"homepage": "
|
|
3
|
+
"version": "0.0.9",
|
|
4
|
+
"homepage": "https://github.com/emamid/svelte-data-table",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite dev",
|
|
7
7
|
"build": "vite build && npm run package",
|
|
8
8
|
"preview": "vite preview",
|
|
9
|
-
"package": "svelte-kit sync && svelte-package && publint",
|
|
9
|
+
"package": "svelte-kit sync && svelte-package && npm run jsdoc && publint",
|
|
10
10
|
"prepublishOnly": "npm run package",
|
|
11
11
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
12
12
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|