Skip to content

Commit b39afec

Browse files
committed
updated readme
1 parent 40403a7 commit b39afec

16 files changed

+729
-27
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
/node_modules
22
/package-lock.json
3-
/build
43
jjmyers-datatable-*.tgz

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## @jjmyers/datatable
22

3+
### Check out the [DEMO WEBSITE](https://joshbot-debug.github.io/datatable)
4+
35
A server sided datatable equiped with every commonly used filter.
46

57
## Quick Features

build/index.d.ts

+317
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,317 @@
1+
import * as react_jsx_runtime from 'react/jsx-runtime';
2+
import styleInject from '/home/josh/Projects/@jjmyers/datatable/node_modules/style-inject/dist/style-inject.es.js';
3+
import * as react from 'react';
4+
5+
var css_248z = ".myers-datatable .table-container {\n display: table;\n border-collapse: collapse;\n}\n.myers-datatable .table-row {\n display: table-row;\n position: relative;\n}\n.myers-datatable .table-cell {\n display: table-cell;\n}\n.myers-datatable .table-header {\n z-index: 1;\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: 15px;\n height: 15px;\n animation: spin 1s linear infinite;\n margin-left: 5px;\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}\n.myers-datatable .spinner-container {\n position: absolute;\n background-color: white;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n display: flex;\n align-items: center;\n}";
6+
styleInject(css_248z);
7+
8+
declare namespace Datatable {
9+
10+
type PartialKeys<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
11+
12+
type Include<T, U> = T extends U ? T : never
13+
14+
type Datatype = "string" | "boolean" | "date" | "datetime" | "image" | "link" | "email" | "phone" | "name" | "paragraph" | "number";
15+
16+
type Filters = { [F in Datatype]?: React.ReactNode };
17+
18+
type Column<FieldNames extends string> = {
19+
field: FieldNames;
20+
columnName: string;
21+
sortable: boolean;
22+
filterable: boolean;
23+
omit: boolean;
24+
renderCell?: (value: any, column: Column<FieldNames>, row: Record<FieldNames, any>) => React.ReactNode;
25+
setOptions?: string[];
26+
multiFilter?: boolean;
27+
} & ({
28+
datatype: Include<Datatype, "string" | "link" | "email" | "phone" | "name" | "paragraph" | "image">;
29+
filterOperations?: UseOperationFilter.TextFilterOperations[];
30+
} | {
31+
datatype: Include<Datatype, "date" | "datetime" | "number">;
32+
filterOperations?: UseOperationFilter.RangeFilterOperations[];
33+
} | {
34+
datatype: Include<Datatype, "boolean">;
35+
filterOperations?: UseOperationFilter.BooleanFilterOperations[];
36+
})
37+
38+
type RowOptionMenuProps = { row: Record<FieldNames, any>; rowIndex: number; }
39+
40+
type AppsPanelProps = { OmitColumns: React.ReactNode; }
41+
42+
type ColumnConfig<FieldNames> = PartialKeys<Column<FieldNames>, "datatype" | "sortable" | "columnName" | "omit" | "filterable">[];
43+
44+
interface Config<FieldNames> {
45+
46+
columns: Datatable.ColumnConfig<FieldNames>;
47+
count: number;
48+
numberOfRows: number;
49+
50+
onFilter?: (filter: Filter<FieldNames>) => void;
51+
52+
initialSortOrder?: Filter<FieldNames>["sortOrder"];
53+
initialPage?: Filter<FieldNames>["page"];
54+
initialOperationFilter?: Filter<FieldNames>["operationFilter"];
55+
initialSetFilter?: Filter<FieldNames>["setFilter"];
56+
}
57+
58+
59+
interface RichDatatableProps<Data extends Record<string, any>, FieldNames> {
60+
data?: Data[];
61+
isFetching?: boolean;
62+
columns: Datatable.ColumnConfig<FieldNames>;
63+
setFilter: Datatable.UseSetFilter.HookReturn<FieldNames>;
64+
operationFilter: Datatable.UseOperationFilter.HookReturn<string>;
65+
sortable: Datatable.UseSortable.HookReturn<FieldNames>;
66+
pagination: Datatable.UsePagination.HookReturn;
67+
selectable: Datatable.UseSelectable.HookReturn<FieldNames>;
68+
RowOptionMenu?: React.FC<RowOptionMenuProps>;
69+
AppsPanel?: React.FC<AppsPanelProps>;
70+
isSelectable?: (row: Record<FieldNames, any>) => boolean;
71+
NoData?: React.ReactNode;
72+
onRowClick?: (row: Record<FieldNames, any>, e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
73+
showOptionsOnRowClick?: boolean;
74+
}
75+
76+
interface Filter<FieldNames> {
77+
sortOrder?: UseSortable.SortOrder<FieldNames>;
78+
page?: UsePagination.Page;
79+
operationFilter?: UseOperationFilter.OperationFilter<TextFilterOperations | RangeFilterOperations | BooleanFilterOperations>;
80+
setFilter?: UseSetFilter.SetFilter<FieldNames>;
81+
}
82+
83+
84+
interface TableHeaderProps<FieldNames extends string> extends React.PropsWithChildren {
85+
column: Column<FieldNames>;
86+
onClick?: (column: Column<FieldNames>) => void;
87+
className?: string;
88+
}
89+
90+
type DatatableFilterProps<Operation> = { multiFilter?: boolean; setOptions?: string[]; datatype: string; field: string; filterOperations?: Operation[] };
91+
92+
interface DatatableProps<FieldNames extends string> {
93+
columns: Datatable.Column<FieldNames>[];
94+
data: Record<FieldNames, any>[];
95+
isFetching?: boolean;
96+
onColumnClick?: (column: Datatable.Column<FieldNames>) => void;
97+
98+
RowOptionMenu?: React.FC<RowOptionMenuProps>
99+
AppsPanel?: React.ReactNode;
100+
101+
renderFilter?: (column: Datatable.Column<FieldNames>, FilterMenu: React.FC<{ hasFilter: boolean; } & React.PropsWithChildren>) => React.ReactElement;
102+
renderSort?: (column: Datatable.Column<FieldNames>) => React.ReactElement;
103+
Footer?: React.ReactNode;
104+
105+
hideSelect?: boolean;
106+
SelectHeader?: React.FC;
107+
SelectCell?: React.FC<{ index: number; row: Record<FieldNames, any> }>;
108+
NoData?: React.ReactNode;
109+
onRowClick?: (row: Record<FieldNames, any>, e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
110+
showOptionsOnRowClick?: boolean;
111+
}
112+
113+
114+
115+
namespace UseSortable {
116+
117+
interface Config<FieldNames extends string> {
118+
initialSortOrder?: SortOrder<FieldNames>;
119+
onChange: (sortOrder: SortOrder<FieldNames>) => void;
120+
}
121+
122+
interface HookReturn<FieldNames extends string> {
123+
sortOrder: SortOrder<FieldNames>;
124+
Sort: (props: SortProps<FieldNames>) => JSX.Element | null;
125+
onSort: (column: Column<FieldNames>) => void
126+
}
127+
128+
interface SortProps<FieldNames extends string> {
129+
column: Column<FieldNames>;
130+
sortDirection?: SortDirection;
131+
orderIndex?: number;
132+
isMultiSort: boolean;
133+
}
134+
135+
type SortDirection = "asc" | "desc"
136+
137+
type SortOrder<FieldNames extends string> = {
138+
[K in FieldNames]?: {
139+
sortDirection: SortDirection;
140+
orderIndex: number;
141+
}
142+
}
143+
}
144+
145+
146+
namespace UsePagination {
147+
148+
interface Config {
149+
initialPage?: Page;
150+
numberOfRows: number;
151+
count: number;
152+
onChange: (page: Page) => void;
153+
}
154+
155+
interface HookReturn {
156+
page: Page;
157+
count: number;
158+
numberOfRows: number;
159+
Pagination: (props: PageProps) => JSX.Element | null;
160+
161+
goToPage: (page: number) => void;
162+
nextPage: () => void;
163+
previousPage: () => void;
164+
lastPage: () => void;
165+
firstPage: () => void;
166+
onChangeRowsPerPage: (rowsPerPage: number) => void;
167+
}
168+
169+
170+
interface PageProps {
171+
page: Page;
172+
count: number;
173+
numberOfRows: number;
174+
goToPage: (page: number) => void;
175+
nextPage: () => void;
176+
previousPage: () => void;
177+
lastPage: () => void;
178+
firstPage: () => void;
179+
onChangeRowsPerPage: (rowsPerPage: number) => void;
180+
}
181+
182+
183+
interface Page {
184+
currentPage: number;
185+
rowsPerPage: number[];
186+
currentRowsPerPage: number;
187+
}
188+
189+
}
190+
191+
192+
namespace UseSelectable {
193+
194+
interface Config<FieldNames> {
195+
numberOfRows: number;
196+
onChange: (selectable: { isAllSelected: boolean; selectedRows: number[] }) => void;
197+
}
198+
199+
interface HookReturn<FieldNames> {
200+
Header: (props: HeaderProps) => JSX.Element | null;
201+
Row: (props: RowProps<FieldNames>) => JSX.Element | null;
202+
selectAll: (select: boolean) => void;
203+
selectedRows: number[];
204+
onSelectRow: (checked: boolean, rowIndex: number) => void;
205+
isAllSelected: boolean;
206+
onDisableRow: (disabled: boolean, rowIndex: number) => void;
207+
}
208+
209+
interface HeaderProps {
210+
selectAll: (select: boolean) => void;
211+
isAllSelected: boolean;
212+
}
213+
214+
interface RowProps<FieldNames> {
215+
index: number;
216+
disabled: boolean;
217+
checked: boolean;
218+
onChange: (checked: boolean, rowIndex: number) => void;
219+
}
220+
221+
}
222+
223+
224+
namespace UseSetFilter {
225+
226+
interface Config<FieldNames> {
227+
onChange: (setFilter: SetFilter<FieldNames>) => void;
228+
initialSetFilter?: SetFilter<FieldNames>;
229+
}
230+
231+
type SetFilter<FieldNames> = { [F in FieldNames]?: string[] };
232+
233+
interface HookReturn<FieldNames> {
234+
SetFilter: (props: SetFilterProps) => JSX.Element | null;
235+
setFilter: SetFilter<FieldNames>;
236+
onSetFilter: (filter: SetFilter<FieldNames>) => void;
237+
}
238+
239+
240+
interface SetFilterProps {
241+
field: string;
242+
options: string[];
243+
onChange: (result: SetFilter) => void;
244+
defaultValue?: string[]
245+
}
246+
247+
}
248+
249+
namespace UseOperationFilter {
250+
251+
interface Config {
252+
onChange: (setFilter: SetFilter) => void;
253+
initialOperationFilter?: OperationFilter;
254+
}
255+
256+
type OperationValue<Operation> = {
257+
operation: Operation;
258+
value?: string;
259+
and?: OperationValue<Operation>
260+
or?: OperationValue<Operation>
261+
}
262+
263+
type OperationFilter<Operation> = {
264+
[field: string]: OperationValue<Operation>
265+
};
266+
267+
interface HookReturn<Operation> {
268+
OperationFilter: (props: OperationProps<Operation>) => JSX.Element | null;
269+
operationFilter: OperationFilter<Operation>;
270+
onSetOperationFilter: (filter: OperationFilter<Operation>) => void;
271+
}
272+
273+
type BooleanFilterOperations = "Is true" | "Is false" | "Is blank";
274+
275+
type RangeFilterOperations = "Equal" | "Not equal" | "Greater than or equal" | "Less than or equal" | "Greater than" | "Less than" | "Is blank";
276+
277+
type TextFilterOperations = "Equal" | "Not equal" | "Contains" | "Starts with" | "Ends with" | "Is blank";
278+
279+
interface OperationProps<Operation> {
280+
inputType?: "text" | "date" | "datetime-local" | "number";
281+
field: string;
282+
onChange: (result: UseOperationFilter.OperationFilter<Operation>) => void;
283+
filterOperations?: Operation[];
284+
currentValue?: UseOperationFilter.OperationValue<Operation>
285+
allowedOperations: Operation[];
286+
}
287+
288+
}
289+
}
290+
291+
declare function BaseDatatable<FieldNames extends string>(props: Datatable.DatatableProps<FieldNames>): react_jsx_runtime.JSX.Element;
292+
293+
declare function useDatatable<FieldNames>(config: Datatable.Config<FieldNames>): {
294+
columns: Datatable.ColumnConfig<FieldNames>;
295+
sortable: Datatable.UseSortable.HookReturn<string>;
296+
pagination: Datatable.UsePagination.HookReturn;
297+
selectable: Datatable.UseSelectable.HookReturn<string>;
298+
setFilter: Datatable.UseSetFilter.HookReturn<FieldNames>;
299+
operationFilter: Datatable.UseOperationFilter.HookReturn<string>;
300+
updateFilter: react.Dispatch<react.SetStateAction<Datatable.Filter<FieldNames>>>;
301+
Datatable: typeof RichDatatable;
302+
};
303+
declare function RichDatatable<Data extends Record<string, any>, FieldNames extends string>(props: Datatable.RichDatatableProps<Data, FieldNames>): react_jsx_runtime.JSX.Element;
304+
305+
interface Props<FieldNames extends string> {
306+
columns: Datatable.Column<FieldNames>[];
307+
setColumns: (callback: (columns: Datatable.Column<FieldNames>[]) => Datatable.Column<FieldNames>[]) => void;
308+
}
309+
declare function OmitColumn<FieldNames extends string>(config: Props<FieldNames>): react_jsx_runtime.JSX.Element;
310+
311+
declare function usePagination(config: Datatable.UsePagination.Config): Datatable.UsePagination.HookReturn;
312+
313+
declare function useSelectable<FieldNames extends string>(config: Datatable.UseSelectable.Config<FieldNames>): Datatable.UseSelectable.HookReturn<FieldNames>;
314+
315+
declare function useSortable<FieldNames extends string>(config: Datatable.UseSortable.Config<FieldNames>): Datatable.UseSortable.HookReturn<FieldNames>;
316+
317+
export { BaseDatatable, Datatable, OmitColumn, useDatatable, usePagination, useSelectable, useSortable };

build/index.esm.js

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

build/index.esm.js.map

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

build/index.js

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

build/index.js.map

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

0 commit comments

Comments
 (0)