aio-table 9.2.1 → 9.3.1
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/index.d.ts +11 -7
- package/index.js +33 -12
- package/package.json +2 -3
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
import
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import * as UT from 'aio-utils';
|
|
3
3
|
import "./index.css";
|
|
4
4
|
type I_rowOption<T, R> = (p: I_rowDetail<T>) => R;
|
|
5
5
|
type I_cellOption<T, R> = ((p: I_cellDetail<T>) => R) | string;
|
|
@@ -14,11 +14,11 @@ type I_cellDetail<T> = I_rowDetail<T> & {
|
|
|
14
14
|
change: (newRow: T) => void;
|
|
15
15
|
isDate: boolean;
|
|
16
16
|
};
|
|
17
|
-
export type I_table_paging = I_paging;
|
|
18
|
-
export type I_table_sort<T> = I_sort<T>;
|
|
19
|
-
export type I_table_filter = I_filter;
|
|
20
|
-
export type I_table_filter_item = I_filter_item;
|
|
21
|
-
export type I_table_filter_saved_item = I_filter_saved_item;
|
|
17
|
+
export type I_table_paging = UT.I_paging;
|
|
18
|
+
export type I_table_sort<T> = UT.I_sort<T>;
|
|
19
|
+
export type I_table_filter = UT.I_filter;
|
|
20
|
+
export type I_table_filter_item = UT.I_filter_item;
|
|
21
|
+
export type I_table_filter_saved_item = UT.I_filter_saved_item;
|
|
22
22
|
export type I_table_column<T> = {
|
|
23
23
|
title?: any;
|
|
24
24
|
sort?: true | I_table_sort<T>;
|
|
@@ -94,6 +94,10 @@ export type I_table<T> = {
|
|
|
94
94
|
filter?: I_table_filter;
|
|
95
95
|
gap?: [number, number];
|
|
96
96
|
striped?: [string, string];
|
|
97
|
+
visibleColumns?: {
|
|
98
|
+
[columnId: string]: boolean | undefined;
|
|
99
|
+
};
|
|
100
|
+
onChangeColumns?: (v: I_table_column<any>[]) => void;
|
|
97
101
|
};
|
|
98
102
|
declare const AIOTable: <T>(props: I_table<T>) => import("react/jsx-runtime").JSX.Element;
|
|
99
103
|
export default AIOTable;
|
package/index.js
CHANGED
|
@@ -13,7 +13,6 @@ import AIOInput from "aio-input";
|
|
|
13
13
|
import * as UT from 'aio-utils';
|
|
14
14
|
import usePopup from "aio-popup";
|
|
15
15
|
import AIODate from "aio-date";
|
|
16
|
-
import { Filterbar, usePaging, useSort } from "aio-component-utils";
|
|
17
16
|
import "./index.css";
|
|
18
17
|
const Context = createContext({});
|
|
19
18
|
const Provider = (p) => _jsx(Context.Provider, { value: p.value, children: p.children });
|
|
@@ -33,11 +32,17 @@ const AIOTable = (props) => {
|
|
|
33
32
|
const getRowsIndexDic = () => rowsIndexDicRef.current;
|
|
34
33
|
const propsRef = useRef(props);
|
|
35
34
|
propsRef.current = props;
|
|
36
|
-
const pagingHook = usePaging({ rows: props.value, paging: props.paging, onChange: props.onChangePaging });
|
|
35
|
+
const pagingHook = UT.usePaging({ rows: props.value, paging: props.paging, onChange: props.onChangePaging });
|
|
37
36
|
const tableHook = useTable(() => propsRef.current, () => props.paging);
|
|
38
37
|
const getIconRef = useRef(new UT.GetSvg());
|
|
39
38
|
const getIcon = getIconRef.current.getIcon;
|
|
40
|
-
const DragColumns = UT.useDrag((dragIndex, dropIndex, reOrder) =>
|
|
39
|
+
const DragColumns = UT.useDrag((dragIndex, dropIndex, reOrder) => {
|
|
40
|
+
const newColumns = reOrder(columns, dragIndex, dropIndex);
|
|
41
|
+
if (props.onChangeColumns) {
|
|
42
|
+
props.onChangeColumns(newColumns);
|
|
43
|
+
}
|
|
44
|
+
setColumns(newColumns);
|
|
45
|
+
});
|
|
41
46
|
const getGetValue = (sort, column) => {
|
|
42
47
|
if (sort.getValue) {
|
|
43
48
|
return sort.getValue;
|
|
@@ -72,7 +77,15 @@ const AIOTable = (props) => {
|
|
|
72
77
|
}
|
|
73
78
|
return sorts;
|
|
74
79
|
};
|
|
75
|
-
const
|
|
80
|
+
const isColumnVisible = (column) => {
|
|
81
|
+
const { visibleColumns = {} } = props;
|
|
82
|
+
const { filterId } = column;
|
|
83
|
+
if (!filterId) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return !!visibleColumns[filterId];
|
|
87
|
+
};
|
|
88
|
+
const sortHook = UT.useSort({
|
|
76
89
|
sorts: [],
|
|
77
90
|
rows: propsRef.current.value,
|
|
78
91
|
onChangeRows: props.onChange,
|
|
@@ -108,7 +121,6 @@ const AIOTable = (props) => {
|
|
|
108
121
|
}, []);
|
|
109
122
|
useEffect(() => {
|
|
110
123
|
if (props.paging) {
|
|
111
|
-
debugger;
|
|
112
124
|
pagingHook.changePaging(props.paging);
|
|
113
125
|
}
|
|
114
126
|
}, [JSON.stringify(props.paging)]);
|
|
@@ -233,6 +245,7 @@ const AIOTable = (props) => {
|
|
|
233
245
|
}
|
|
234
246
|
}
|
|
235
247
|
const changeCell = (cellDetail, cellNewValue) => {
|
|
248
|
+
if (cellNewValue) { }
|
|
236
249
|
if (!props.onChange) {
|
|
237
250
|
return;
|
|
238
251
|
}
|
|
@@ -250,10 +263,10 @@ const AIOTable = (props) => {
|
|
|
250
263
|
let attrs = UT.AddToAttrs(props.attrs, { className: ['aio-table', props.className], style: Object.assign({ gap: gap[1] }, props.style), attrs: { ref: dom } });
|
|
251
264
|
const context = {
|
|
252
265
|
rootProps: props, getTimeText, isDate, columns, excelColumns, filterColumns, changeCell, tableHook, sortHook, ROWS,
|
|
253
|
-
getRowsIndexDic, add, remove, search, exportToExcel, DragColumns, getIcon, popup,
|
|
266
|
+
getRowsIndexDic, add, remove, search, exportToExcel, DragColumns, getIcon, popup, isColumnVisible
|
|
254
267
|
};
|
|
255
268
|
return (_jsxs(Provider, { value: context, children: [_jsxs("div", Object.assign({}, attrs, { children: [_jsx(TableToolbar, {}), !!props.filter &&
|
|
256
|
-
_jsx(Filterbar, { columns: filterColumns, filter: props.filter, fa: props.fa, columnOption: { text: (column) => column.title, id: (column) => column.filterId, type: (column) => column.type || 'text' } }), _jsxs("div", { className: 'aio-table-unit aio-table-scroll', style: { gap: gap[1] }, children: [_jsx(TableHeader, {}), _jsx(TableRows, {})] }), pagingHook.render()] })), popup.render()] }));
|
|
269
|
+
_jsx(UT.Filterbar, { columns: filterColumns, filter: props.filter, fa: props.fa, columnOption: { text: (column) => column.title, id: (column) => column.filterId, type: (column) => column.type || 'text' } }), _jsxs("div", { className: 'aio-table-unit aio-table-scroll', style: { gap: gap[1] }, children: [_jsx(TableHeader, {}), _jsx(TableRows, {})] }), pagingHook.render()] })), popup.render()] }));
|
|
257
270
|
};
|
|
258
271
|
export default AIOTable;
|
|
259
272
|
const TableRows = () => {
|
|
@@ -319,8 +332,11 @@ const TableHeader = () => {
|
|
|
319
332
|
return _jsxs("div", Object.assign({}, headerAttrs, { children: [Titles, RemoveTitle] }));
|
|
320
333
|
};
|
|
321
334
|
const TableTitle = (p) => {
|
|
322
|
-
const { column,
|
|
323
|
-
let { tableHook, DragColumns } = useProvider();
|
|
335
|
+
const { column, colIndex } = p;
|
|
336
|
+
let { tableHook, DragColumns, isColumnVisible } = useProvider();
|
|
337
|
+
if (!isColumnVisible(column)) {
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
324
340
|
const attrs = Object.assign(Object.assign(Object.assign({}, tableHook.getTitleAttrs(column)), DragColumns.getDragAttrs(colIndex)), DragColumns.getDropAttrs(colIndex));
|
|
325
341
|
return _jsx("div", Object.assign({}, attrs, { children: attrs.title }));
|
|
326
342
|
};
|
|
@@ -328,12 +344,16 @@ const TableRow = (props) => {
|
|
|
328
344
|
const { rowDetail } = props;
|
|
329
345
|
const { row, rowIndex } = rowDetail;
|
|
330
346
|
const rowId = row._id;
|
|
331
|
-
let { remove, rootProps, columns, tableHook, getIcon, isDate } = useProvider();
|
|
347
|
+
let { remove, rootProps, columns, tableHook, getIcon, isDate, isColumnVisible } = useProvider();
|
|
332
348
|
const isOdd = rowIndex % 2 === 0;
|
|
333
349
|
function getCells() {
|
|
334
|
-
return columns.map((column
|
|
350
|
+
return columns.map((column) => {
|
|
351
|
+
if (!isColumnVisible(column)) {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
335
354
|
const key = rowId + ' ' + column._id;
|
|
336
355
|
const cellDetail = Object.assign(Object.assign({}, rowDetail), { column, change: (cellNewValue) => {
|
|
356
|
+
if (cellNewValue) { }
|
|
337
357
|
if (!rootProps.onChange) {
|
|
338
358
|
return;
|
|
339
359
|
}
|
|
@@ -353,7 +373,7 @@ const TableRow = (props) => {
|
|
|
353
373
|
};
|
|
354
374
|
const TableCell = (props) => {
|
|
355
375
|
const { cellDetail, cellValue, isOdd } = props;
|
|
356
|
-
const { row, column
|
|
376
|
+
const { row, column } = cellDetail;
|
|
357
377
|
const { tableHook, getTimeText, rootProps } = useProvider();
|
|
358
378
|
const { template, before, after, subtext } = column;
|
|
359
379
|
const rowId = row._id;
|
|
@@ -390,6 +410,7 @@ const useTable = (getProps, getPaging) => {
|
|
|
390
410
|
let type = typeof cellValue;
|
|
391
411
|
if (type === 'string') {
|
|
392
412
|
const { row } = cellDetail;
|
|
413
|
+
if (row) { }
|
|
393
414
|
let result = cellValue;
|
|
394
415
|
if (getValue[cellValue]) {
|
|
395
416
|
result = getValue[cellValue](cellDetail);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aio-table",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.3.1",
|
|
4
4
|
"description": "all in one table. tree mode , simple mode , tree mode, gantt mode , groupby mode, freeze mode.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -19,8 +19,7 @@
|
|
|
19
19
|
"homepage": "https://github.com/mohammadFeiz/aio-table#readme",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"aio-input": "latest",
|
|
22
|
-
"aio-utils": "latest"
|
|
23
|
-
"aio-component-utils":"latest"
|
|
22
|
+
"aio-utils": "latest"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
25
|
"react-scripts": "latest"
|