aio-table 9.3.1 → 11.0.0
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 +9 -6
- package/index.js +143 -122
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ type I_rowDetail<T> = {
|
|
|
12
12
|
type I_cellDetail<T> = I_rowDetail<T> & {
|
|
13
13
|
column: I_table_column<T>;
|
|
14
14
|
change: (newRow: T) => void;
|
|
15
|
-
|
|
15
|
+
date: number[];
|
|
16
16
|
};
|
|
17
17
|
export type I_table_paging = UT.I_paging;
|
|
18
18
|
export type I_table_sort<T> = UT.I_sort<T>;
|
|
@@ -22,10 +22,10 @@ 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>;
|
|
25
|
+
jalali?: boolean;
|
|
25
26
|
filterId?: string;
|
|
26
27
|
search?: boolean;
|
|
27
|
-
id
|
|
28
|
-
_id?: string;
|
|
28
|
+
id: string;
|
|
29
29
|
width?: any;
|
|
30
30
|
minWidth?: any;
|
|
31
31
|
excel?: string | boolean;
|
|
@@ -41,7 +41,10 @@ export type I_table_column<T> = {
|
|
|
41
41
|
titleAttrs?: {
|
|
42
42
|
[attrs: string]: any;
|
|
43
43
|
};
|
|
44
|
-
type?: 'text' | 'number' | '
|
|
44
|
+
type?: 'text' | 'number' | 'date';
|
|
45
|
+
show?: boolean;
|
|
46
|
+
pattern?: string;
|
|
47
|
+
data?: any;
|
|
45
48
|
};
|
|
46
49
|
export type I_table<T> = {
|
|
47
50
|
fa?: boolean;
|
|
@@ -94,8 +97,8 @@ export type I_table<T> = {
|
|
|
94
97
|
filter?: I_table_filter;
|
|
95
98
|
gap?: [number, number];
|
|
96
99
|
striped?: [string, string];
|
|
97
|
-
|
|
98
|
-
[
|
|
100
|
+
columnOption?: {
|
|
101
|
+
[key in keyof I_table_column<any>]?: (p: I_cellDetail<any>) => any;
|
|
99
102
|
};
|
|
100
103
|
onChangeColumns?: (v: I_table_column<any>[]) => void;
|
|
101
104
|
};
|
package/index.js
CHANGED
|
@@ -21,7 +21,6 @@ const AIOTable = (props) => {
|
|
|
21
21
|
const popup = usePopup();
|
|
22
22
|
let [dom] = useState(createRef());
|
|
23
23
|
let [searchValue, setSearchValue] = useState('');
|
|
24
|
-
const [columns, setColumns] = useState([]);
|
|
25
24
|
const [searchColumns, setSearchColumns] = useState([]);
|
|
26
25
|
const [excelColumns, setExcelColumns] = useState([]);
|
|
27
26
|
const [filterColumns, setFilterColumns] = useState([]);
|
|
@@ -33,24 +32,46 @@ const AIOTable = (props) => {
|
|
|
33
32
|
const propsRef = useRef(props);
|
|
34
33
|
propsRef.current = props;
|
|
35
34
|
const pagingHook = UT.usePaging({ rows: props.value, paging: props.paging, onChange: props.onChangePaging });
|
|
36
|
-
const
|
|
35
|
+
const getColumnOption = (key, cellDetails) => {
|
|
36
|
+
const columnValue = cellDetails.column[key];
|
|
37
|
+
if (columnValue !== undefined) {
|
|
38
|
+
const { getValue = {} } = props;
|
|
39
|
+
if (getValue[columnValue]) {
|
|
40
|
+
return getValue[columnValue](cellDetails);
|
|
41
|
+
}
|
|
42
|
+
return cellDetails.column[key];
|
|
43
|
+
}
|
|
44
|
+
const { columnOption } = props;
|
|
45
|
+
const fn = (columnOption || {})[key] || (() => { });
|
|
46
|
+
const res = fn(cellDetails);
|
|
47
|
+
if (res !== undefined) {
|
|
48
|
+
return res;
|
|
49
|
+
}
|
|
50
|
+
if (key === 'value') {
|
|
51
|
+
return cellDetails.row[cellDetails.column.id];
|
|
52
|
+
}
|
|
53
|
+
const defaults = { show: true, title: '', justify: false, titleAttrs: {} };
|
|
54
|
+
return defaults[key];
|
|
55
|
+
};
|
|
56
|
+
const tableHook = useTable(() => propsRef.current, () => props.paging, getColumnOption);
|
|
37
57
|
const getIconRef = useRef(new UT.GetSvg());
|
|
38
58
|
const getIcon = getIconRef.current.getIcon;
|
|
39
59
|
const DragColumns = UT.useDrag((dragIndex, dropIndex, reOrder) => {
|
|
40
|
-
const newColumns = reOrder(columns, dragIndex, dropIndex);
|
|
60
|
+
const newColumns = reOrder(props.columns || [], dragIndex, dropIndex);
|
|
41
61
|
if (props.onChangeColumns) {
|
|
42
62
|
props.onChangeColumns(newColumns);
|
|
43
63
|
}
|
|
44
|
-
|
|
45
|
-
});
|
|
64
|
+
}, 'aio-table-title', 'aio-table-unit');
|
|
46
65
|
const getGetValue = (sort, column) => {
|
|
47
66
|
if (sort.getValue) {
|
|
48
67
|
return sort.getValue;
|
|
49
68
|
}
|
|
50
69
|
return (row) => {
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
70
|
+
const cellDetail = tableHook.getCellDetail({ column, row });
|
|
71
|
+
const type = getColumnOption('type', cellDetail) || 'text';
|
|
72
|
+
const value = getColumnOption('value', cellDetail);
|
|
73
|
+
const cellValue = tableHook.getCellValue(cellDetail, value);
|
|
74
|
+
if (type === 'date') {
|
|
54
75
|
const DATE = new AIODate();
|
|
55
76
|
try {
|
|
56
77
|
return DATE.getTime(cellValue);
|
|
@@ -66,38 +87,37 @@ const AIOTable = (props) => {
|
|
|
66
87
|
let sorts = [];
|
|
67
88
|
for (let i = 0; i < columns.length; i++) {
|
|
68
89
|
const column = columns[i];
|
|
69
|
-
const {
|
|
70
|
-
const
|
|
90
|
+
const cellDetail = tableHook.getCellDetail({ column });
|
|
91
|
+
const columnId = getColumnOption('id', cellDetail);
|
|
92
|
+
const sortValue = getColumnOption('sort', cellDetail);
|
|
93
|
+
const sort = sortValue === true ? { sortId: columnId } : sortValue;
|
|
71
94
|
if (!sort) {
|
|
72
95
|
continue;
|
|
73
96
|
}
|
|
74
97
|
let { active = false, dir = 'dec', sortId } = sort;
|
|
75
|
-
let sortItem = { dir, title: sort.title ||
|
|
98
|
+
let sortItem = { dir, title: sort.title || getColumnOption('title', cellDetail), sortId, active, getValue: getGetValue(sort, column) };
|
|
76
99
|
sorts.push(sortItem);
|
|
77
100
|
}
|
|
78
101
|
return sorts;
|
|
79
102
|
};
|
|
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
103
|
const sortHook = UT.useSort({
|
|
89
104
|
sorts: [],
|
|
90
105
|
rows: propsRef.current.value,
|
|
91
106
|
onChangeRows: props.onChange,
|
|
92
107
|
onChangeSort: props.onChangeSort,
|
|
93
108
|
});
|
|
94
|
-
const isDate = (column) => ['month', 'day', 'hour', 'minute'].indexOf(column.type || 'text') !== -1;
|
|
95
109
|
function getColumns() {
|
|
96
110
|
let { columns = [] } = props;
|
|
97
111
|
let searchColumns = [], excelColumns = [], filterColumns = [];
|
|
98
|
-
let updatedColumns = columns.map((
|
|
99
|
-
|
|
100
|
-
|
|
112
|
+
let updatedColumns = columns.map((column, i) => {
|
|
113
|
+
const cellDetail = tableHook.getCellDetail({ column });
|
|
114
|
+
const filterId = getColumnOption('filterId', cellDetail);
|
|
115
|
+
const search = getColumnOption('search', cellDetail);
|
|
116
|
+
const excel = getColumnOption('excel', cellDetail);
|
|
117
|
+
const id = getColumnOption('id', cellDetail);
|
|
118
|
+
if (id === undefined) {
|
|
119
|
+
console.error(`aio-table error => missing column id in props.columns[${i}]`);
|
|
120
|
+
}
|
|
101
121
|
if (search) {
|
|
102
122
|
searchColumns.push(column);
|
|
103
123
|
}
|
|
@@ -109,7 +129,9 @@ const AIOTable = (props) => {
|
|
|
109
129
|
}
|
|
110
130
|
return column;
|
|
111
131
|
});
|
|
112
|
-
|
|
132
|
+
if (props.onChangeColumns) {
|
|
133
|
+
props.onChangeColumns(updatedColumns);
|
|
134
|
+
}
|
|
113
135
|
setSearchColumns(searchColumns);
|
|
114
136
|
setExcelColumns(excelColumns);
|
|
115
137
|
setFilterColumns(filterColumns);
|
|
@@ -124,27 +146,6 @@ const AIOTable = (props) => {
|
|
|
124
146
|
pagingHook.changePaging(props.paging);
|
|
125
147
|
}
|
|
126
148
|
}, [JSON.stringify(props.paging)]);
|
|
127
|
-
function getTimeText(column, value) {
|
|
128
|
-
if (!value || value === null) {
|
|
129
|
-
return '';
|
|
130
|
-
}
|
|
131
|
-
const t = column.type;
|
|
132
|
-
const DATE = new AIODate();
|
|
133
|
-
let pattern = '{year}/{month}';
|
|
134
|
-
if (t !== 'month') {
|
|
135
|
-
pattern += '/{day}';
|
|
136
|
-
if (t !== 'day') {
|
|
137
|
-
pattern += ' {hour}';
|
|
138
|
-
if (t === 'minute') {
|
|
139
|
-
pattern += ' : {minute}';
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
pattern += ' : 00';
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return DATE.getDateByPattern(value, pattern);
|
|
147
|
-
}
|
|
148
149
|
function add() {
|
|
149
150
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
151
|
if (!props.onAdd) {
|
|
@@ -178,11 +179,14 @@ const AIOTable = (props) => {
|
|
|
178
179
|
const isLast = rowIndex === props.value.length - 1;
|
|
179
180
|
let row = props.value[rowIndex], json = {};
|
|
180
181
|
for (let j = 0; j < excelColumns.length; j++) {
|
|
181
|
-
const column = excelColumns[j]
|
|
182
|
+
const column = excelColumns[j];
|
|
183
|
+
const cellDetail = tableHook.getCellDetail({ row, rowIndex, isFirst, isLast, column });
|
|
184
|
+
const excel = getColumnOption('excel', cellDetail);
|
|
182
185
|
let key = '';
|
|
183
186
|
if (excel === true) {
|
|
184
|
-
|
|
185
|
-
|
|
187
|
+
const title = getColumnOption('title', cellDetail);
|
|
188
|
+
if (typeof title === 'string') {
|
|
189
|
+
key = title;
|
|
186
190
|
}
|
|
187
191
|
else {
|
|
188
192
|
key = 'untitle';
|
|
@@ -194,8 +198,8 @@ const AIOTable = (props) => {
|
|
|
194
198
|
else {
|
|
195
199
|
continue;
|
|
196
200
|
}
|
|
197
|
-
const
|
|
198
|
-
json[key] = tableHook.getCellValue(cellDetail,
|
|
201
|
+
const value = getColumnOption('value', cellDetail);
|
|
202
|
+
json[key] = tableHook.getCellValue(cellDetail, value, '');
|
|
199
203
|
}
|
|
200
204
|
list.push(json);
|
|
201
205
|
}
|
|
@@ -215,8 +219,9 @@ const AIOTable = (props) => {
|
|
|
215
219
|
let str = '';
|
|
216
220
|
for (let i = 0; i < searchColumns.length; i++) {
|
|
217
221
|
let column = searchColumns[i];
|
|
218
|
-
const cellDetail = { row, rowIndex, isFirst, isLast, column
|
|
219
|
-
|
|
222
|
+
const cellDetail = tableHook.getCellDetail({ row, rowIndex, isFirst, isLast, column });
|
|
223
|
+
const value = getColumnOption('value', cellDetail);
|
|
224
|
+
let cellValue = tableHook.getCellValue(cellDetail, value, '');
|
|
220
225
|
if (cellValue) {
|
|
221
226
|
str += cellValue + ' ';
|
|
222
227
|
}
|
|
@@ -244,29 +249,19 @@ const AIOTable = (props) => {
|
|
|
244
249
|
props.onSearch(searchValue);
|
|
245
250
|
}
|
|
246
251
|
}
|
|
247
|
-
const changeCell = (cellDetail, cellNewValue) => {
|
|
248
|
-
if (cellNewValue) { }
|
|
249
|
-
if (!props.onChange) {
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
const { column } = cellDetail;
|
|
253
|
-
if (typeof column.value !== 'string' || column.value.indexOf('row.') !== 0) {
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
let row = JSON.parse(JSON.stringify(cellDetail.row));
|
|
257
|
-
const rowId = row._id;
|
|
258
|
-
eval(`${column.value} = cellNewValue`);
|
|
259
|
-
props.onChange(props.value.map((o) => o._id !== rowId ? o : row));
|
|
260
|
-
};
|
|
261
252
|
let ROWS = getRows();
|
|
262
253
|
const { gap = [0, 1] } = props;
|
|
263
254
|
let attrs = UT.AddToAttrs(props.attrs, { className: ['aio-table', props.className], style: Object.assign({ gap: gap[1] }, props.style), attrs: { ref: dom } });
|
|
264
255
|
const context = {
|
|
265
|
-
rootProps: props,
|
|
266
|
-
getRowsIndexDic, add, remove, search, exportToExcel, DragColumns, getIcon, popup,
|
|
256
|
+
rootProps: props, excelColumns, filterColumns, tableHook, sortHook, ROWS,
|
|
257
|
+
getRowsIndexDic, add, remove, search, exportToExcel, DragColumns, getIcon, popup, getColumnOption
|
|
267
258
|
};
|
|
268
259
|
return (_jsxs(Provider, { value: context, children: [_jsxs("div", Object.assign({}, attrs, { children: [_jsx(TableToolbar, {}), !!props.filter &&
|
|
269
|
-
_jsx(UT.Filterbar, { columns: filterColumns, filter: props.filter, fa: props.fa, columnOption: {
|
|
260
|
+
_jsx(UT.Filterbar, { columns: filterColumns, filter: props.filter, fa: props.fa, columnOption: {
|
|
261
|
+
text: (column) => getColumnOption('title', tableHook.getCellDetail({ column })),
|
|
262
|
+
id: (column) => getColumnOption('filterId', tableHook.getCellDetail({ column })),
|
|
263
|
+
type: (column) => getColumnOption('type', tableHook.getCellDetail({ column })) || 'text'
|
|
264
|
+
} }), _jsxs("div", { className: 'aio-table-unit aio-table-scroll', style: { gap: gap[1] }, children: [_jsx(TableHeader, {}), _jsx(TableRows, {})] }), pagingHook.render()] })), popup.render()] }));
|
|
270
265
|
};
|
|
271
266
|
export default AIOTable;
|
|
272
267
|
const TableRows = () => {
|
|
@@ -324,17 +319,20 @@ const TableToolbar = () => {
|
|
|
324
319
|
_jsx("div", { className: 'aio-table-search', children: _jsx(AIOInput, { type: 'text', onChange: (value) => search(value), after: getIcon('mdiMagnify', 0.7) }) }), sortHook.renderSortButton(), !!excelColumns.length && _jsx("div", { className: 'aio-table-toolbar-button', onClick: () => exportToExcel(), children: getIcon('mdiFileExcel', 0.8) }), !!onAdd && _jsx("div", { className: 'aio-table-toolbar-button', onClick: () => add(), children: getAddText() })] })));
|
|
325
320
|
};
|
|
326
321
|
const TableHeader = () => {
|
|
327
|
-
let { rootProps,
|
|
328
|
-
let { headerAttrs, onRemove, gap = [0, 1] } = rootProps;
|
|
322
|
+
let { rootProps, getColumnOption, tableHook } = useProvider();
|
|
323
|
+
let { headerAttrs, onRemove, gap = [0, 1], columns = [] } = rootProps;
|
|
329
324
|
headerAttrs = UT.AddToAttrs(headerAttrs, { className: 'aio-table-header', style: { gap: gap[0] } });
|
|
330
|
-
let Titles = columns.map((
|
|
325
|
+
let Titles = columns.map((column, i) => {
|
|
326
|
+
const columnId = getColumnOption('id', tableHook.getCellDetail({ column }));
|
|
327
|
+
return _jsx(TableTitle, { column: column, isLast: i === columns.length - 1, colIndex: i }, columnId);
|
|
328
|
+
});
|
|
331
329
|
let RemoveTitle = !onRemove ? null : _jsx("div", { className: 'aio-table-remove-title' });
|
|
332
330
|
return _jsxs("div", Object.assign({}, headerAttrs, { children: [Titles, RemoveTitle] }));
|
|
333
331
|
};
|
|
334
332
|
const TableTitle = (p) => {
|
|
335
333
|
const { column, colIndex } = p;
|
|
336
|
-
let { tableHook, DragColumns,
|
|
337
|
-
if (!
|
|
334
|
+
let { tableHook, DragColumns, getColumnOption } = useProvider();
|
|
335
|
+
if (!getColumnOption('show', tableHook.getCellDetail({ column }))) {
|
|
338
336
|
return null;
|
|
339
337
|
}
|
|
340
338
|
const attrs = Object.assign(Object.assign(Object.assign({}, tableHook.getTitleAttrs(column)), DragColumns.getDragAttrs(colIndex)), DragColumns.getDropAttrs(colIndex));
|
|
@@ -344,27 +342,19 @@ const TableRow = (props) => {
|
|
|
344
342
|
const { rowDetail } = props;
|
|
345
343
|
const { row, rowIndex } = rowDetail;
|
|
346
344
|
const rowId = row._id;
|
|
347
|
-
let { remove, rootProps,
|
|
345
|
+
let { remove, rootProps, tableHook, getIcon, getColumnOption } = useProvider();
|
|
346
|
+
const { columns = [] } = rootProps;
|
|
348
347
|
const isOdd = rowIndex % 2 === 0;
|
|
349
348
|
function getCells() {
|
|
350
349
|
return columns.map((column) => {
|
|
351
|
-
if (!
|
|
350
|
+
if (!getColumnOption('show', tableHook.getCellDetail(Object.assign(Object.assign({}, rowDetail), { column })))) {
|
|
352
351
|
return null;
|
|
353
352
|
}
|
|
354
|
-
const
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
if (typeof column.value !== 'string' || column.value.indexOf('row.') !== 0) {
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
let row = JSON.parse(JSON.stringify(cellDetail.row));
|
|
364
|
-
eval(`${column.value} = cellNewValue`);
|
|
365
|
-
rootProps.onChange(rootProps.value.map((o) => o._id !== rowId ? o : row));
|
|
366
|
-
}, isDate: isDate(column) });
|
|
367
|
-
const cellValue = tableHook.getCellValue(cellDetail, column.value);
|
|
353
|
+
const cellDetail = tableHook.getCellDetail(Object.assign(Object.assign({}, rowDetail), { column, change: (v) => tableHook.changeCell(tableHook.getCellDetail(Object.assign(Object.assign({}, rowDetail), { column })), v) }));
|
|
354
|
+
const columnId = getColumnOption('id', cellDetail);
|
|
355
|
+
const key = rowId + ' ' + columnId;
|
|
356
|
+
const value = getColumnOption('value', cellDetail);
|
|
357
|
+
const cellValue = tableHook.getCellValue(cellDetail, value);
|
|
368
358
|
return (_jsx(TableCell, { cellDetail: cellDetail, cellValue: cellValue, isOdd: isOdd }, key));
|
|
369
359
|
});
|
|
370
360
|
}
|
|
@@ -372,24 +362,49 @@ const TableRow = (props) => {
|
|
|
372
362
|
return (_jsx(_Fragment, { children: _jsxs("div", Object.assign({}, tableHook.getRowAttrs(props.rowDetail, isOdd), { children: [getCells(), onRemove ? _jsx("button", { className: 'aio-table-remove', onClick: () => remove(row, rowIndex), children: getIcon('mdiClose', 0.8) }) : null] }), rowId) }));
|
|
373
363
|
};
|
|
374
364
|
const TableCell = (props) => {
|
|
375
|
-
|
|
365
|
+
let { cellDetail, cellValue, isOdd } = props;
|
|
376
366
|
const { row, column } = cellDetail;
|
|
377
|
-
const { tableHook,
|
|
378
|
-
const {
|
|
367
|
+
const { tableHook, rootProps, getColumnOption } = useProvider();
|
|
368
|
+
const { columnOption } = rootProps;
|
|
369
|
+
const type = getColumnOption('type', cellDetail);
|
|
370
|
+
if (type === 'number') {
|
|
371
|
+
cellValue = UT.SplitNumber(cellValue);
|
|
372
|
+
}
|
|
373
|
+
const before = getColumnOption('before', cellDetail);
|
|
374
|
+
const after = getColumnOption('after', cellDetail);
|
|
375
|
+
const subtext = getColumnOption('subtext', cellDetail);
|
|
379
376
|
const rowId = row._id;
|
|
380
|
-
const colId =
|
|
381
|
-
const
|
|
382
|
-
|
|
377
|
+
const colId = getColumnOption('id', cellDetail);
|
|
378
|
+
const getTemplateValue = () => {
|
|
379
|
+
const { getValue = {} } = rootProps;
|
|
380
|
+
if (typeof column.template === 'function') {
|
|
381
|
+
return column.template(cellDetail);
|
|
382
|
+
}
|
|
383
|
+
if (typeof column.template === 'string' && getValue[column.template]) {
|
|
384
|
+
return getValue[column.template](cellDetail);
|
|
385
|
+
}
|
|
386
|
+
if ((columnOption || {}).template) {
|
|
387
|
+
return columnOption.template(cellDetail);
|
|
388
|
+
}
|
|
389
|
+
const pattern = getColumnOption('pattern', cellDetail);
|
|
390
|
+
if (pattern) {
|
|
391
|
+
if (type === 'date') {
|
|
392
|
+
return new AIODate().getDateByPattern(cellValue, pattern);
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
return pattern.replace('{value}', cellValue);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
const templateValue = getTemplateValue();
|
|
383
400
|
const beforeValue = tableHook.getCellValue(cellDetail, before, undefined);
|
|
384
401
|
const afterValue = tableHook.getCellValue(cellDetail, after, undefined);
|
|
385
402
|
const subtextValue = tableHook.getCellValue(cellDetail, subtext, undefined);
|
|
386
403
|
return (_jsx(Fragment, { children: _jsxs("div", Object.assign({}, tableHook.getCellAttrs(props.cellDetail, props.cellValue, isOdd, rootProps.striped), { children: [beforeValue !== undefined && _jsx("div", { className: "aio-table-cell-before", children: beforeValue }), _jsxs("div", { className: `aio-table-cell-value${subtext !== undefined ? ' has-subtext' : ''}`, "data-subtext": subtextValue, children: [templateValue !== undefined && templateValue, templateValue === undefined && cellValue] }), afterValue !== undefined && _jsx("div", { className: "aio-table-cell-after", children: afterValue })] })) }, rowId + ' ' + colId));
|
|
387
404
|
};
|
|
388
|
-
const useTable = (getProps, getPaging) => {
|
|
389
|
-
const DragRows = UT.useDrag((
|
|
390
|
-
const { onSwap, onChange } = getProps();
|
|
391
|
-
const { dragIndex } = dragData;
|
|
392
|
-
const { dropIndex, rows } = dropData;
|
|
405
|
+
const useTable = (getProps, getPaging, getColumnOption) => {
|
|
406
|
+
const DragRows = UT.useDrag((dragIndex, dropIndex, reOrder) => {
|
|
407
|
+
const { onSwap, onChange, value: rows } = getProps();
|
|
393
408
|
const newRows = reOrder(rows, dragIndex, dropIndex);
|
|
394
409
|
const from = rows[dragIndex];
|
|
395
410
|
const to = rows[dropIndex];
|
|
@@ -399,7 +414,7 @@ const useTable = (getProps, getPaging) => {
|
|
|
399
414
|
else if (onChange) {
|
|
400
415
|
onChange(newRows);
|
|
401
416
|
}
|
|
402
|
-
});
|
|
417
|
+
}, 'aio-table-row', 'aio-table-rows');
|
|
403
418
|
const getCellValue = (cellDetail, cellValue, def) => {
|
|
404
419
|
const { getValue = {} } = getProps();
|
|
405
420
|
const paging = getPaging();
|
|
@@ -433,24 +448,28 @@ const useTable = (getProps, getPaging) => {
|
|
|
433
448
|
}
|
|
434
449
|
return cellValue === undefined ? def : cellValue;
|
|
435
450
|
};
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
result = colValue(column);
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
result = colValue;
|
|
451
|
+
function changeCell(cellDetail, newRow) {
|
|
452
|
+
if (newRow) { }
|
|
453
|
+
const { onChange, value: propsValue } = getProps();
|
|
454
|
+
if (!onChange) {
|
|
455
|
+
return;
|
|
445
456
|
}
|
|
446
|
-
|
|
447
|
-
|
|
457
|
+
const rowId = cellDetail.row._id;
|
|
458
|
+
onChange(propsValue.map((o) => o._id !== rowId ? o : newRow));
|
|
459
|
+
}
|
|
460
|
+
function getCellDetail(v) {
|
|
461
|
+
const res = Object.assign({ column: {}, row: {}, rowIndex: 0, isFirst: false, isLast: false, date: [], change: () => { } }, v);
|
|
462
|
+
const value = getColumnOption('value', res);
|
|
463
|
+
const jalali = getColumnOption('jalali', res);
|
|
464
|
+
const date = res.column.type === 'date' ? new AIODate().convertToArray(getCellValue(res, value), jalali) : [];
|
|
465
|
+
return Object.assign(Object.assign(Object.assign({}, res), { date }), v);
|
|
466
|
+
}
|
|
448
467
|
const getCellAttrs = (cellDetail, cellValue, isOdd, striped) => {
|
|
449
468
|
const { column } = cellDetail;
|
|
450
469
|
const attrs = getCellValue(cellDetail, column.attrs, {});
|
|
451
|
-
const justify =
|
|
452
|
-
const width =
|
|
453
|
-
const minWidth =
|
|
470
|
+
const justify = getColumnOption('justify', cellDetail);
|
|
471
|
+
const width = getColumnOption('width', cellDetail);
|
|
472
|
+
const minWidth = getColumnOption('minWidth', cellDetail);
|
|
454
473
|
const className = `aio-table-cell` + (justify ? ` aio-table-cell-justify` : '');
|
|
455
474
|
const style = { width, minWidth, flex: width ? undefined : 1 };
|
|
456
475
|
if (striped) {
|
|
@@ -459,13 +478,15 @@ const useTable = (getProps, getPaging) => {
|
|
|
459
478
|
return UT.AddToAttrs(attrs, { className: [className, isOdd ? 'aio-table-cell-odd' : 'aio-table-cell-even'], style, attrs: { title: typeof cellValue === 'string' ? cellValue : undefined } });
|
|
460
479
|
};
|
|
461
480
|
const getTitleAttrs = (column) => {
|
|
462
|
-
const
|
|
463
|
-
const
|
|
464
|
-
const
|
|
465
|
-
const
|
|
481
|
+
const cellDetail = getCellDetail({ column });
|
|
482
|
+
const attrs = getColumnOption('titleAttrs', cellDetail);
|
|
483
|
+
const justify = getColumnOption('justify', cellDetail);
|
|
484
|
+
const width = getColumnOption('width', cellDetail);
|
|
485
|
+
const minWidth = getColumnOption('minWidth', cellDetail);
|
|
466
486
|
const className = `aio-table-title` + (justify ? ` aio-table-title-justify` : '');
|
|
467
487
|
const style = { width, minWidth, flex: width ? undefined : 1 };
|
|
468
|
-
|
|
488
|
+
const title = getColumnOption('title', cellDetail);
|
|
489
|
+
return UT.AddToAttrs(attrs, { className, style, attrs: { title: typeof title === 'string' ? title : undefined } });
|
|
469
490
|
};
|
|
470
491
|
const getRowAttrs = (rowDetail, isOdd) => {
|
|
471
492
|
const { rowOption = {}, onSwap, value, gap = [0, 1] } = getProps();
|
|
@@ -477,5 +498,5 @@ const useTable = (getProps, getPaging) => {
|
|
|
477
498
|
}
|
|
478
499
|
return obj;
|
|
479
500
|
};
|
|
480
|
-
return { getCellValue,
|
|
501
|
+
return { getCellValue, getCellAttrs, getTitleAttrs, getRowAttrs, changeCell, getCellDetail };
|
|
481
502
|
};
|