aio-table 9.3.0 → 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 +5 -1
- package/index.js +24 -5
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
2
|
import * as UT from 'aio-utils';
|
|
3
3
|
import "./index.css";
|
|
4
4
|
type I_rowOption<T, R> = (p: I_rowDetail<T>) => R;
|
|
@@ -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
|
@@ -36,7 +36,13 @@ const AIOTable = (props) => {
|
|
|
36
36
|
const tableHook = useTable(() => propsRef.current, () => props.paging);
|
|
37
37
|
const getIconRef = useRef(new UT.GetSvg());
|
|
38
38
|
const getIcon = getIconRef.current.getIcon;
|
|
39
|
-
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
|
+
});
|
|
40
46
|
const getGetValue = (sort, column) => {
|
|
41
47
|
if (sort.getValue) {
|
|
42
48
|
return sort.getValue;
|
|
@@ -71,6 +77,14 @@ const AIOTable = (props) => {
|
|
|
71
77
|
}
|
|
72
78
|
return sorts;
|
|
73
79
|
};
|
|
80
|
+
const isColumnVisible = (column) => {
|
|
81
|
+
const { visibleColumns = {} } = props;
|
|
82
|
+
const { filterId } = column;
|
|
83
|
+
if (!filterId) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return !!visibleColumns[filterId];
|
|
87
|
+
};
|
|
74
88
|
const sortHook = UT.useSort({
|
|
75
89
|
sorts: [],
|
|
76
90
|
rows: propsRef.current.value,
|
|
@@ -107,7 +121,6 @@ const AIOTable = (props) => {
|
|
|
107
121
|
}, []);
|
|
108
122
|
useEffect(() => {
|
|
109
123
|
if (props.paging) {
|
|
110
|
-
debugger;
|
|
111
124
|
pagingHook.changePaging(props.paging);
|
|
112
125
|
}
|
|
113
126
|
}, [JSON.stringify(props.paging)]);
|
|
@@ -250,7 +263,7 @@ 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
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()] }));
|
|
@@ -320,7 +333,10 @@ const TableHeader = () => {
|
|
|
320
333
|
};
|
|
321
334
|
const TableTitle = (p) => {
|
|
322
335
|
const { column, colIndex } = p;
|
|
323
|
-
let { tableHook, DragColumns } = useProvider();
|
|
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,10 +344,13 @@ 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
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) => {
|
|
337
356
|
if (cellNewValue) { }
|