Skip to content

Commit 6efaf5d

Browse files
committed
updated major
1 parent c5aa31a commit 6efaf5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+171414
-100110
lines changed

Diff for: README.md

+34-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## @jjmyers/datatable
22

3+
### The styling of the datatable can be customized.
34
### Check out the [DEMO WEBSITE](https://joshbot-debug.github.io/datatable)
45

56
A datatable equiped with every commonly used filter. The demo has an array of 10,000 records. Not all features are active here.
@@ -31,27 +32,47 @@ import "@jjmyers/datatable/build/styles/default.css"
3132
```tsx
3233

3334
import { useDatatable, type Datatable } from "@jjmyers/datatable";
34-
import "@jjmyers/datatable/build/styles/default.css"
35+
import "@jjmyers/datatable/build/styles/default.css" // OR elegance.css
36+
37+
const status = ["online", "offline", "available", "unavailable", "dnd"]
38+
39+
type Data = {
40+
id: number;
41+
status: string;
42+
fullName: string;
43+
// ...more fields
44+
}
45+
3546

3647
function MyListOfData() {
3748

3849
const [isFetching, setIsFetching] = useState(false);
3950

40-
const { Datatable, ...controller } = useDatatable({
51+
const { Datatable, ...controller } = useDatatable<Data>({
4152
data: data, // An array of objects
4253
count: data.length, // This is the total number of records in the database
4354
serverSide: false, // If this is false, data manipulation will be handled client sided. DEFAULT: true
4455
onFilter: console.log, // If serverSide is true, you need to handle the filters here and update data.
56+
4557
columns: [
46-
{ field: "emp_id", datatype: "number", sortable: false },
47-
{ field: "name", datatype: "string", multiFilter: true },
48-
{ field: "email", datatype: "email", },
49-
{ field: "dob", datatype: "date" },
50-
{ field: "image", datatype: "image" },
58+
// There are more props
59+
// You'll have to check them yourself
60+
{ field: "id", width: 85, datatype: "number" },
61+
{ field: "status", setOptions: status, multiFilter: true },
62+
{ field: "fullName", width: 250 },
63+
{ field: "firstName" },
64+
{ field: "middleName" },
65+
{ field: "lastName" },
66+
{ field: "email", width: 250, datatype: "email" },
5167
{ field: "phone", datatype: "phone" },
52-
{ field: "is_active", datatype: "boolean"},
53-
{ field: "bio", datatype: "paragraph" },
54-
68+
{ field: "isActive", datatype: "boolean" },
69+
{ field: "profileImage", datatype: "image", omit: true },
70+
{ field: "website", width: 250, datatype: "link" },
71+
{ field: "loginTime", datatype: "time" },
72+
{ field: "dateOfBirth", width: 180, datatype: "date" },
73+
{ field: "about", width: 500, datatype: "paragraph" },
74+
{ field: "createdAt", width: 250, datatype: "datetime" },
75+
5576
// For custom fields that do not exist in "data", use @ts-ignore
5677
// @ts-ignore
5778
{ field: "customField" },
@@ -61,21 +82,15 @@ function MyListOfData() {
6182
// Just an example of how you can add buttons here and manipulate the datatable if needed.
6283
const AppsPanel = ({ OmitColumns }: Datatable.AppsPanelProps) => (
6384
<>
64-
<button onClick={() => controller.selectable.selectAll(true)} style={{ padding: 8 }}>Check All</button>
65-
<button onClick={() => controller.selectable.selectAll(false)} style={{ padding: 8 }}>Uncheck All</button>
66-
<button onClick={() => controller.updateFilter(prev => ({ ...prev, ["custom"]: "Hello!" }))} style={{ padding: 8 }}>Custom filter option</button>
67-
<button onClick={() => setIsFetching(p => !p)} style={{ padding: 8 }}>Bulk update</button>
68-
<button onClick={() => controller.pagination.lastPage()} style={{ padding: 8 }}>Last page</button>
85+
<button onClick={() => controller.reset()} style={{ padding: 8 }}>Reset Filters</button>
6986
{OmitColumns}
7087
</>
7188
)
7289

7390
// Just an exmple of adding options to rows
7491
const RowOptionMenu = ({ row, rowIndex }: Datatable.RowOptionMenuProps) => (<>
75-
<div onClick={() => setIsFetching(p => !p)} style={{ padding: 8 }}>Row Option 1</div>
76-
<div onClick={() => setIsFetching(p => !p)} style={{ padding: 8 }}>Row Option 2</div>
77-
<div onClick={() => setIsFetching(p => !p)} style={{ padding: 8 }}>Row Option 3</div>
78-
<div onClick={() => setIsFetching(p => !p)} style={{ padding: 8 }}>Row Option 4</div>
92+
<div onClick={() => {}} style={{ padding: 8 }}>Row Option 1</div>
93+
<div onClick={() => {}} style={{ padding: 8 }}>Row Option 2</div>
7994
</>);
8095

8196

Diff for: build/index.d.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
22
import styleInject from '/home/josh/Projects/@jjmyers/datatable/node_modules/style-inject/dist/style-inject.es.js';
33
import * as react from 'react';
44

5-
var css_248z = ".myers-datatable .table-container {\n display: flex;\n flex-direction: column;\n}\n.myers-datatable .table-row {\n border-collapse: collapse;\n display: flex;\n}\n.myers-datatable .table-cell {\n display: flex;\n flex-direction: column;\n justify-content: center;\n}\n.myers-datatable .table-header-row {\n z-index: 1;\n}\n.myers-datatable .spinner-background {\n position: absolute;\n background-color: white;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n}\n.myers-datatable .spinner-row {\n display: flex;\n align-items: center;\n}\n.myers-datatable .spinner {\n border: 4px solid #f3f3f3; /* Light grey */\n border-top: 4px solid #7e7e7e; /* Blue */\n border-radius: 50%;\n width: 20px;\n height: 20px;\n animation: spin 1s linear infinite;\n margin-left: 5px;\n}\n.myers-datatable .spinner-row {\n z-index: 1;\n position: absolute;\n width: 100%;\n}\n.myers-datatable .spinner-loading-text {\n margin-left: 10px;\n}\n@keyframes spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}";
5+
var css_248z = ".myers-datatable .table-container {\n display: flex;\n flex-direction: column;\n}\n.myers-datatable .table-row {\n display: flex;\n width: -moz-fit-content;\n width: fit-content;\n}\n.myers-datatable .table-cell {\n display: flex;\n flex-direction: column;\n justify-content: center;\n}\n.myers-datatable .table-header-row {\n z-index: 1;\n}\n.myers-datatable .spinner-background {\n position: absolute;\n background-color: white;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n}\n.myers-datatable .spinner-row {\n display: flex;\n align-items: center;\n}\n.myers-datatable .spinner {\n border: 4px solid #f3f3f3; /* Light grey */\n border-top: 4px solid #7e7e7e; /* Blue */\n border-radius: 50%;\n width: 20px;\n height: 20px;\n animation: spin 1s linear infinite;\n margin-left: 5px;\n}\n.myers-datatable .spinner-row {\n z-index: 1;\n position: absolute;\n width: 100%;\n}\n.myers-datatable .spinner-loading-text {\n margin-left: 10px;\n}\n@keyframes spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}";
66
styleInject(css_248z);
77

88
declare namespace Datatable {
@@ -74,10 +74,10 @@ declare namespace Datatable {
7474
isFetching?: boolean;
7575
columns: Datatable.ColumnConfig<Data>;
7676
setFilter: Datatable.UseSetFilter.HookReturn<Data>;
77-
operationFilter: Datatable.UseOperationFilter.HookReturn<string>;
77+
operationFilter: Datatable.UseOperationFilter.HookReturn<Data, any>;
7878
sortable: Datatable.UseSortable.HookReturn<Data>;
7979
pagination: Datatable.UsePagination.HookReturn;
80-
selectable: Datatable.UseSelectable.HookReturn<Data>;
80+
selectable: Datatable.UseSelectable.HookReturn;
8181
RowOptionMenu?: React.FC<RowOptionMenuProps<Data>>;
8282
AppsPanel?: React.FC<AppsPanelProps>;
8383
isSelectable?: (row: Data) => boolean;
@@ -136,7 +136,8 @@ declare namespace Datatable {
136136
interface HookReturn<Data extends Record<string, any>> {
137137
sortOrder: SortOrder<Data>;
138138
Sort: (props: SortProps<Data>) => JSX.Element | null;
139-
onSort: (column: DatatableColumn<Data>) => void
139+
onSort: (column: DatatableColumn<Data>) => void;
140+
reset: () => void;
140141
}
141142

142143
interface SortProps<Data> {
@@ -178,6 +179,7 @@ declare namespace Datatable {
178179
lastPage: () => void;
179180
firstPage: () => void;
180181
onChangeRowsPerPage: (rowsPerPage: number) => void;
182+
reset: () => void;
181183
}
182184

183185

@@ -218,6 +220,7 @@ declare namespace Datatable {
218220
onSelectRow: (checked: boolean, rowIndex: number) => void;
219221
isAllSelected: boolean;
220222
onDisableRow: (disabled: boolean, rowIndex: number) => void;
223+
reset: () => void;
221224
}
222225

223226
interface HeaderProps {
@@ -248,6 +251,7 @@ declare namespace Datatable {
248251
SetFilter: (props: SetFilterProps) => JSX.Element | null;
249252
setFilter: SetFilter<Data>;
250253
onSetFilter: (filter: SetFilter<Data>) => void;
254+
reset: () => void;
251255
}
252256

253257

@@ -275,20 +279,21 @@ declare namespace Datatable {
275279
}
276280

277281
type OperationFilter<Data extends Record<string, any>, Operation> = {
278-
[key: keyof Data]: OperationValue<Operation>
282+
[K in keyof Data]?: OperationValue<Operation>
279283
};
280284

281285
interface HookReturn<Data extends Record<string, any>, Operation> {
282286
OperationFilter: (props: OperationProps<Data, Operation>) => JSX.Element | null;
283287
operationFilter: OperationFilter<Data, Operation>;
284288
onSetOperationFilter: (filter: OperationFilter<Data, Operation>) => void;
289+
reset: () => void;
285290
}
286291

287-
type BooleanFilterOperations = "Is true" | "Is false" | "Is blank";
292+
type BooleanFilterOperations = "Is true" | "Is false" | "Is blank" | "Not blank";
288293

289-
type RangeFilterOperations = "Equal" | "Not equal" | "Greater than or equal" | "Less than or equal" | "Greater than" | "Less than" | "Is blank";
294+
type RangeFilterOperations = "Equal" | "Not equal" | "Greater than or equal" | "Less than or equal" | "Greater than" | "Less than" | "Is blank" | "Not blank";
290295

291-
type TextFilterOperations = "Equal" | "Not equal" | "Contains" | "Starts with" | "Ends with" | "Is blank";
296+
type TextFilterOperations = "Equal" | "Not equal" | "Contains" | "Starts with" | "Ends with" | "Is blank" | "Not blank";
292297

293298
interface OperationProps<Data extends Record<string, any>, Operation> {
294299
inputType?: "text" | "date" | "datetime-local" | "number" | "time";
@@ -314,6 +319,7 @@ declare function useDatatable<Data extends Record<string, any>>(config: Datatabl
314319
operationFilter: Datatable.UseOperationFilter.HookReturn<Data, string>;
315320
updateFilter: react.Dispatch<react.SetStateAction<Datatable.Filter<Data>>>;
316321
Datatable: typeof RichDatatable;
322+
reset: () => void;
317323
};
318324
declare function RichDatatable<Data extends Record<string, any>>(props: Datatable.RichDatatableProps<Data>): react_jsx_runtime.JSX.Element;
319325

Diff for: build/index.esm.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: build/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: build/styles/default.css

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
}
1515
.myers-datatable .table-scroll-container {
1616
flex: 1;
17-
overflow: auto;
17+
overflow-y: scroll;
18+
overflow-x: auto;
1819
position: relative;
1920
}
2021
.myers-datatable .table-cell {
@@ -43,6 +44,7 @@
4344
padding-inline: 0px;
4445
padding-block: 0px;
4546
overflow: visible;
47+
position: relative;
4648
}
4749
.myers-datatable .table-header-children-container {
4850
display: flex;

0 commit comments

Comments
 (0)