qbs-react-grid 1.2.1 → 1.2.2
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/dist/css/qbs-react-grid.css +1 -1095
- package/dist/css/qbs-react-grid.min.css +1 -1
- package/dist/css/qbs-react-grid.min.css.map +1 -1
- package/es/Table.js +19 -19
- package/es/less/index.less +3 -0
- package/es/qbsTable/QbsTable.js +34 -7
- package/es/qbsTable/TableCardList.d.ts +5 -0
- package/es/qbsTable/TableCardList.js +564 -0
- package/es/qbsTable/Toolbar.js +16 -2
- package/es/qbsTable/commontypes.d.ts +9 -0
- package/es/qbsTable/utilities/CardComponent.d.ts +12 -0
- package/es/qbsTable/utilities/CardComponent.js +64 -0
- package/es/qbsTable/utilities/CardMenuDropdown.d.ts +13 -0
- package/es/qbsTable/utilities/CardMenuDropdown.js +89 -0
- package/es/qbsTable/utilities/SwitchCardColumns.d.ts +2 -0
- package/es/qbsTable/utilities/SwitchCardColumns.js +24 -0
- package/es/qbsTable/utilities/icons.d.ts +3 -0
- package/es/qbsTable/utilities/icons.js +45 -0
- package/es/utils/getTotalByColumns.js +1 -1
- package/es/utils/mergeCells.js +1 -1
- package/es/utils/useCellDescriptor.js +11 -11
- package/es/utils/useClassNames.js +2 -0
- package/lib/Table.js +19 -19
- package/lib/less/index.less +3 -0
- package/lib/qbsTable/QbsTable.js +34 -7
- package/lib/qbsTable/TableCardList.d.ts +5 -0
- package/lib/qbsTable/TableCardList.js +571 -0
- package/lib/qbsTable/Toolbar.js +16 -2
- package/lib/qbsTable/commontypes.d.ts +9 -0
- package/lib/qbsTable/utilities/CardComponent.d.ts +12 -0
- package/lib/qbsTable/utilities/CardComponent.js +72 -0
- package/lib/qbsTable/utilities/CardMenuDropdown.d.ts +13 -0
- package/lib/qbsTable/utilities/CardMenuDropdown.js +95 -0
- package/lib/qbsTable/utilities/SwitchCardColumns.d.ts +2 -0
- package/lib/qbsTable/utilities/SwitchCardColumns.js +30 -0
- package/lib/qbsTable/utilities/icons.d.ts +3 -0
- package/lib/qbsTable/utilities/icons.js +50 -2
- package/lib/utils/getTotalByColumns.js +1 -1
- package/lib/utils/mergeCells.js +1 -1
- package/lib/utils/useCellDescriptor.js +11 -11
- package/lib/utils/useClassNames.js +2 -0
- package/package.json +11 -6
- package/src/less/index.less +3 -0
- package/src/qbsTable/QbsTable.tsx +201 -173
- package/src/qbsTable/TableCardList.tsx +629 -0
- package/src/qbsTable/Toolbar.tsx +22 -2
- package/src/qbsTable/commontypes.ts +9 -0
- package/src/qbsTable/utilities/CardComponent.tsx +102 -0
- package/src/qbsTable/utilities/CardMenuDropdown.tsx +118 -0
- package/src/qbsTable/utilities/SwitchCardColumns.tsx +29 -0
- package/src/qbsTable/utilities/icons.tsx +51 -0
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import Cell from '../Cell';
|
|
4
|
+
import Column from '../Column';
|
|
5
|
+
import ColumnGroup from '../ColumnGroup';
|
|
6
|
+
import HeaderCell from '../HeaderCell';
|
|
7
|
+
import Pagination from '../Pagination';
|
|
8
|
+
import Table from '../Table';
|
|
9
|
+
import { QbsColumnProps, QbsTableProps } from './commontypes';
|
|
10
|
+
import {
|
|
11
|
+
ActionCell,
|
|
12
|
+
CheckCell,
|
|
13
|
+
CustomRowStatus,
|
|
14
|
+
CustomTableCell,
|
|
15
|
+
ExpandCell
|
|
16
|
+
} from './CustomTableCell';
|
|
17
|
+
import ToolBar from './Toolbar';
|
|
18
|
+
import ColumToggle from './utilities/ColumShowHide';
|
|
19
|
+
import debounce from './utilities/debounce';
|
|
20
|
+
import { deepEqual } from './utilities/deepEqual';
|
|
21
|
+
import NoData from './utilities/empty';
|
|
22
|
+
import { SettingsIcon } from './utilities/icons';
|
|
23
|
+
|
|
24
|
+
// import 'qbs-react-table/dist/css/qbs-react-grid.css';
|
|
25
|
+
|
|
26
|
+
import '../../dist/css/qbs-react-grid.css';
|
|
27
|
+
|
|
28
|
+
const CHECKBOX_LINE_HEIGHT = '36px';
|
|
29
|
+
const COLUMN_WIDTH = 250;
|
|
30
|
+
const QbsTable: React.FC<QbsTableProps> = ({
|
|
31
|
+
handleColumnSort,
|
|
32
|
+
data,
|
|
33
|
+
columns: propColumn,
|
|
34
|
+
sortColumn,
|
|
35
|
+
sortType,
|
|
36
|
+
selection = false,
|
|
37
|
+
onSelect,
|
|
38
|
+
title = 'My Tabl',
|
|
39
|
+
search = false,
|
|
40
|
+
asyncSearch,
|
|
41
|
+
searchValue,
|
|
42
|
+
onSearch,
|
|
43
|
+
handleSearchValue,
|
|
44
|
+
paginationProps = {},
|
|
45
|
+
pagination = false,
|
|
46
|
+
cellBordered = false,
|
|
47
|
+
bordered = false,
|
|
48
|
+
minHeight,
|
|
49
|
+
height = 630,
|
|
50
|
+
onExpandChange,
|
|
51
|
+
wordWrap,
|
|
52
|
+
dataRowKey = 'id',
|
|
53
|
+
defaultExpandAllRows,
|
|
54
|
+
handleRowExpanded,
|
|
55
|
+
shouldUpdateScroll = false,
|
|
56
|
+
rowExpand = false,
|
|
57
|
+
actionProps = [],
|
|
58
|
+
theme,
|
|
59
|
+
handleMenuActions,
|
|
60
|
+
onRowClick,
|
|
61
|
+
expandedRowKeys,
|
|
62
|
+
setExpandedRowKeys,
|
|
63
|
+
primaryFilter,
|
|
64
|
+
advancefilter,
|
|
65
|
+
classes = {},
|
|
66
|
+
toolbar,
|
|
67
|
+
columnToggle = true,
|
|
68
|
+
handleColumnToggle,
|
|
69
|
+
tableHeaderActions,
|
|
70
|
+
isLoading,
|
|
71
|
+
selectedRowActions,
|
|
72
|
+
handleResetColumns,
|
|
73
|
+
selectedRows,
|
|
74
|
+
headerHeight = 40,
|
|
75
|
+
tableBodyHeight,
|
|
76
|
+
customRowStatus,
|
|
77
|
+
searchPlaceholder,
|
|
78
|
+
rowExpandedHeight = 317,
|
|
79
|
+
renderSortIcon,
|
|
80
|
+
tableKey = 'parent',
|
|
81
|
+
renderEmpty,
|
|
82
|
+
autoHeight,
|
|
83
|
+
emptySubTitle,
|
|
84
|
+
emptyTitle
|
|
85
|
+
}) => {
|
|
86
|
+
const [loading, setLoading] = useState(false);
|
|
87
|
+
const [columns, setColumns] = useState(propColumn);
|
|
88
|
+
const [checkedKeys, setCheckedKeys] = useState<(number | string)[]>([]);
|
|
89
|
+
const dataTheme = useMemo(() => localStorage.getItem('theme') ?? theme, [theme]);
|
|
90
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
91
|
+
const prevColumns = useRef<any | null>();
|
|
92
|
+
const tableBodyRef = useRef<HTMLDivElement>(null);
|
|
93
|
+
const handleSortColumn = useCallback(
|
|
94
|
+
(sortColumn: any, sortType: any) => {
|
|
95
|
+
setLoading(true);
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
setLoading(false);
|
|
98
|
+
handleColumnSort?.(sortColumn, sortType);
|
|
99
|
+
}, 500);
|
|
100
|
+
},
|
|
101
|
+
[handleColumnSort]
|
|
102
|
+
);
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (selectedRows) {
|
|
105
|
+
setCheckedKeys(selectedRows ?? ([] as (number | string)[]));
|
|
106
|
+
} else {
|
|
107
|
+
setCheckedKeys([]);
|
|
108
|
+
}
|
|
109
|
+
}, [selectedRows]);
|
|
110
|
+
|
|
111
|
+
const handleChecked = debounce((keys?: any) => {
|
|
112
|
+
onSelect?.(keys);
|
|
113
|
+
}, 500);
|
|
114
|
+
|
|
115
|
+
const handleCheckAll = useCallback(
|
|
116
|
+
(event: React.ChangeEvent<HTMLInputElement>) => {
|
|
117
|
+
const keys = event.target.checked ? data.map(item => item.id) : [];
|
|
118
|
+
// let updatedKeys = [...keys];
|
|
119
|
+
// if (checkedKeys) {
|
|
120
|
+
// updatedKeys = [...checkedKeys, ...updatedKeys];
|
|
121
|
+
// } TODO => previous bug fix removed this section
|
|
122
|
+
const updatedKeys = [...keys];
|
|
123
|
+
setCheckedKeys(updatedKeys);
|
|
124
|
+
handleChecked(updatedKeys);
|
|
125
|
+
},
|
|
126
|
+
[data]
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const handleCheck = useCallback(
|
|
130
|
+
(event: React.ChangeEvent<HTMLInputElement>) => {
|
|
131
|
+
const value = event.target.value;
|
|
132
|
+
if (value !== undefined) {
|
|
133
|
+
const updatedKeys = event.target.checked
|
|
134
|
+
? [...checkedKeys, value]
|
|
135
|
+
: checkedKeys.filter(key => key !== value);
|
|
136
|
+
setCheckedKeys(updatedKeys);
|
|
137
|
+
handleChecked(updatedKeys);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
[checkedKeys]
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const handleToggle = useCallback(
|
|
145
|
+
(columnName: string) => {
|
|
146
|
+
let lastVisibleColumn: any = null;
|
|
147
|
+
let visibleCount = 0;
|
|
148
|
+
|
|
149
|
+
const updatedColumns = columns?.map(col => {
|
|
150
|
+
// Toggle visibility for the matched column
|
|
151
|
+
if (col.title === columnName) {
|
|
152
|
+
col = { ...col, isVisible: !col.isVisible };
|
|
153
|
+
}
|
|
154
|
+
if (col.isVisible) {
|
|
155
|
+
lastVisibleColumn = col;
|
|
156
|
+
visibleCount++;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return col;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
if (visibleCount > 0 && lastVisibleColumn) {
|
|
163
|
+
updatedColumns.forEach(col => {
|
|
164
|
+
if (col.field === lastVisibleColumn?.field && col.title === lastVisibleColumn.title) {
|
|
165
|
+
col.resizable = false;
|
|
166
|
+
} else {
|
|
167
|
+
col.resizable = true;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
setColumns(updatedColumns);
|
|
173
|
+
},
|
|
174
|
+
[columns]
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
const handleColumnWidth = useCallback((newWidth?: number, dataKey?: any) => {
|
|
178
|
+
if (newWidth === undefined || dataKey === undefined) return;
|
|
179
|
+
setColumns(prevColumns =>
|
|
180
|
+
prevColumns.map(column =>
|
|
181
|
+
column.field === dataKey ? { ...column, colWidth: newWidth } : column
|
|
182
|
+
)
|
|
183
|
+
);
|
|
184
|
+
}, []);
|
|
185
|
+
|
|
186
|
+
useEffect(() => {
|
|
187
|
+
if (wordWrap === 'fit-content') {
|
|
188
|
+
setColumns(prevColumns =>
|
|
189
|
+
prevColumns.map(column =>
|
|
190
|
+
column.field ? { ...column, colWidth: calculateWidth(column.field) } : column
|
|
191
|
+
)
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}, [wordWrap]);
|
|
195
|
+
|
|
196
|
+
const onReorder = useCallback((columns: QbsColumnProps[]) => {
|
|
197
|
+
setColumns(columns);
|
|
198
|
+
}, []);
|
|
199
|
+
|
|
200
|
+
// useEffect(() => {
|
|
201
|
+
// }, [columns]);
|
|
202
|
+
|
|
203
|
+
const handleClear = ([]) => {
|
|
204
|
+
setCheckedKeys([]);
|
|
205
|
+
handleChecked([]);
|
|
206
|
+
};
|
|
207
|
+
const toolbarProps = {
|
|
208
|
+
title: title,
|
|
209
|
+
search: search,
|
|
210
|
+
searchValue: searchValue,
|
|
211
|
+
pagination: pagination,
|
|
212
|
+
onSearch: onSearch,
|
|
213
|
+
handleSearchValue: handleSearchValue,
|
|
214
|
+
asyncSearch: asyncSearch,
|
|
215
|
+
paginationProps: paginationProps,
|
|
216
|
+
primaryFilter: primaryFilter,
|
|
217
|
+
advancefilter: advancefilter,
|
|
218
|
+
className: classes?.toolbarClass,
|
|
219
|
+
handleToggle: handleToggle,
|
|
220
|
+
onReorder: onReorder,
|
|
221
|
+
columnToggle: columnToggle,
|
|
222
|
+
columns: columns,
|
|
223
|
+
checkedKeys: checkedKeys,
|
|
224
|
+
tableHeaderActions: tableHeaderActions,
|
|
225
|
+
selectedRowActions: selectedRowActions,
|
|
226
|
+
onSelect: handleClear,
|
|
227
|
+
handleColumnToggle: handleColumnToggle,
|
|
228
|
+
dataLength: data?.length,
|
|
229
|
+
searchPlaceholder: searchPlaceholder
|
|
230
|
+
};
|
|
231
|
+
const themeToggle = useMemo(() => document.getElementById('themeToggle') as HTMLInputElement, []);
|
|
232
|
+
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
const handleThemeToggle = () => {
|
|
235
|
+
if (themeToggle?.checked) {
|
|
236
|
+
document.body.setAttribute('data-theme', 'dark');
|
|
237
|
+
} else {
|
|
238
|
+
document.body.removeAttribute('data-theme');
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const handleDOMContentLoaded = () => {
|
|
243
|
+
if (localStorage.getItem('theme') === 'dark') {
|
|
244
|
+
document.body.setAttribute('data-theme', 'dark');
|
|
245
|
+
if (themeToggle) {
|
|
246
|
+
themeToggle.checked = true;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
themeToggle?.addEventListener('change', handleThemeToggle);
|
|
252
|
+
document.addEventListener('DOMContentLoaded', handleDOMContentLoaded);
|
|
253
|
+
|
|
254
|
+
return () => {
|
|
255
|
+
themeToggle?.removeEventListener('change', handleThemeToggle);
|
|
256
|
+
document.removeEventListener('DOMContentLoaded', handleDOMContentLoaded);
|
|
257
|
+
};
|
|
258
|
+
}, [themeToggle]);
|
|
259
|
+
|
|
260
|
+
const handleExpanded = useCallback(
|
|
261
|
+
(rowData: any) => {
|
|
262
|
+
console.log(rowData);
|
|
263
|
+
const keyValue = dataRowKey as string;
|
|
264
|
+
const key = rowData[keyValue];
|
|
265
|
+
|
|
266
|
+
const nextExpandedRowKeys = new Set(expandedRowKeys);
|
|
267
|
+
|
|
268
|
+
if (nextExpandedRowKeys.has(key)) {
|
|
269
|
+
nextExpandedRowKeys.delete(key);
|
|
270
|
+
} else {
|
|
271
|
+
nextExpandedRowKeys.add(key);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
setExpandedRowKeys?.(Array.from(nextExpandedRowKeys));
|
|
275
|
+
},
|
|
276
|
+
[dataRowKey, expandedRowKeys, setExpandedRowKeys]
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const calculateWidth = (str: string, fontSize = 8, characterWidth = 1) => {
|
|
280
|
+
const result = findLargestCell(str) * fontSize * characterWidth;
|
|
281
|
+
return result > 60 ? result : 60;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
function findLargestCell(columnTitle: string) {
|
|
285
|
+
let largestCellLength = 0;
|
|
286
|
+
data.forEach(row => {
|
|
287
|
+
if (row[columnTitle] && String(row[columnTitle]).length > largestCellLength) {
|
|
288
|
+
largestCellLength = String(row[columnTitle]).length;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
return largestCellLength;
|
|
293
|
+
}
|
|
294
|
+
const handleColumnsResizable = useCallback(() => {
|
|
295
|
+
const filteredColumns = columns?.filter(item => item.isVisible);
|
|
296
|
+
const length = filteredColumns?.length ?? 0;
|
|
297
|
+
const lastVisibleColumn = filteredColumns[length - 1];
|
|
298
|
+
const reColumns = columns?.map(item =>
|
|
299
|
+
item?.field === lastVisibleColumn?.field ? { ...item, resizable: false } : item
|
|
300
|
+
);
|
|
301
|
+
setColumns(reColumns);
|
|
302
|
+
}, [columns]);
|
|
303
|
+
|
|
304
|
+
useEffect(() => {
|
|
305
|
+
setColumns(propColumn);
|
|
306
|
+
}, [propColumn]);
|
|
307
|
+
|
|
308
|
+
useEffect(() => {
|
|
309
|
+
if (!deepEqual(columns, prevColumns.current)) {
|
|
310
|
+
handleColumnsResizable();
|
|
311
|
+
}
|
|
312
|
+
prevColumns.current = columns;
|
|
313
|
+
}, [columns, handleColumnsResizable]);
|
|
314
|
+
const findGrouped = () => {
|
|
315
|
+
return columns?.find(item => item.grouped) ? true : false;
|
|
316
|
+
};
|
|
317
|
+
const columnsRendered: React.ReactElement[] = useMemo(
|
|
318
|
+
() =>
|
|
319
|
+
(columns ?? []).map(
|
|
320
|
+
({
|
|
321
|
+
title,
|
|
322
|
+
field,
|
|
323
|
+
resizable,
|
|
324
|
+
sortable,
|
|
325
|
+
colWidth,
|
|
326
|
+
align,
|
|
327
|
+
grouped,
|
|
328
|
+
groupHeader,
|
|
329
|
+
fixed,
|
|
330
|
+
children,
|
|
331
|
+
customCell,
|
|
332
|
+
renderCell,
|
|
333
|
+
isVisible,
|
|
334
|
+
link,
|
|
335
|
+
getPath,
|
|
336
|
+
rowClick,
|
|
337
|
+
sortKey,
|
|
338
|
+
type,
|
|
339
|
+
hideLink
|
|
340
|
+
}) => (
|
|
341
|
+
<>
|
|
342
|
+
{isVisible && (
|
|
343
|
+
<>
|
|
344
|
+
{grouped ? (
|
|
345
|
+
<ColumnGroup
|
|
346
|
+
header={groupHeader}
|
|
347
|
+
fixed={fixed}
|
|
348
|
+
align={align}
|
|
349
|
+
verticalAlign="middle"
|
|
350
|
+
groupHeaderHeight={40}
|
|
351
|
+
>
|
|
352
|
+
<>
|
|
353
|
+
{children?.map(child => (
|
|
354
|
+
<Column
|
|
355
|
+
key={child.title}
|
|
356
|
+
sortable={child.sortable}
|
|
357
|
+
width={child.colWidth ?? COLUMN_WIDTH}
|
|
358
|
+
resizable={child.resizable}
|
|
359
|
+
align={child.align}
|
|
360
|
+
onResize={handleColumnWidth}
|
|
361
|
+
fixed={child.fixed}
|
|
362
|
+
>
|
|
363
|
+
<HeaderCell
|
|
364
|
+
dataTheme={dataTheme}
|
|
365
|
+
verticalAlign={'middle'}
|
|
366
|
+
className={` ${classes.headerClass}`}
|
|
367
|
+
sortKey={child.sortKey}
|
|
368
|
+
renderSortIcon={renderSortIcon}
|
|
369
|
+
>
|
|
370
|
+
{child.title}
|
|
371
|
+
</HeaderCell>
|
|
372
|
+
{child.customCell || child.link ? (
|
|
373
|
+
<CustomTableCell
|
|
374
|
+
renderCell={child.renderCell}
|
|
375
|
+
dataKey={child.field}
|
|
376
|
+
dataTheme={dataTheme}
|
|
377
|
+
type={child.type}
|
|
378
|
+
path={child.getPath}
|
|
379
|
+
link={child.link}
|
|
380
|
+
/>
|
|
381
|
+
) : (
|
|
382
|
+
<Cell
|
|
383
|
+
className={` ${classes.cellClass}`}
|
|
384
|
+
dataKey={child.field}
|
|
385
|
+
dataTheme={dataTheme}
|
|
386
|
+
/>
|
|
387
|
+
)}
|
|
388
|
+
</Column>
|
|
389
|
+
))}
|
|
390
|
+
</>
|
|
391
|
+
</ColumnGroup>
|
|
392
|
+
) : (
|
|
393
|
+
<Column
|
|
394
|
+
key={title}
|
|
395
|
+
sortable={sortable}
|
|
396
|
+
width={colWidth ?? COLUMN_WIDTH}
|
|
397
|
+
resizable={resizable}
|
|
398
|
+
align={align}
|
|
399
|
+
fixed={fixed}
|
|
400
|
+
onResize={handleColumnWidth}
|
|
401
|
+
>
|
|
402
|
+
<HeaderCell
|
|
403
|
+
dataTheme={dataTheme}
|
|
404
|
+
verticalAlign={findGrouped() ? 'middle' : undefined}
|
|
405
|
+
className={` ${classes.headerClass}`}
|
|
406
|
+
sortKey={sortKey}
|
|
407
|
+
renderSortIcon={renderSortIcon}
|
|
408
|
+
>
|
|
409
|
+
{title}
|
|
410
|
+
</HeaderCell>
|
|
411
|
+
{customCell || link ? (
|
|
412
|
+
<CustomTableCell
|
|
413
|
+
renderCell={renderCell}
|
|
414
|
+
dataKey={field}
|
|
415
|
+
rowClick={rowClick}
|
|
416
|
+
type={type}
|
|
417
|
+
hideLink={hideLink}
|
|
418
|
+
path={getPath}
|
|
419
|
+
dataTheme={dataTheme}
|
|
420
|
+
link={link}
|
|
421
|
+
/>
|
|
422
|
+
) : (
|
|
423
|
+
<Cell
|
|
424
|
+
dataKey={field}
|
|
425
|
+
dataTheme={dataTheme}
|
|
426
|
+
className={` ${classes.cellClass}`}
|
|
427
|
+
/>
|
|
428
|
+
)}
|
|
429
|
+
</Column>
|
|
430
|
+
)}
|
|
431
|
+
</>
|
|
432
|
+
)}
|
|
433
|
+
</>
|
|
434
|
+
)
|
|
435
|
+
),
|
|
436
|
+
[columns, dataTheme]
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
return (
|
|
440
|
+
<div className={`qbs-table ${classes.tableContainerClass}`} data-theme={dataTheme}>
|
|
441
|
+
{toolbar && <ToolBar {...toolbarProps} />}
|
|
442
|
+
<div className="qbs-table-border-wrap">
|
|
443
|
+
<Table
|
|
444
|
+
height={autoHeight ? undefined : height}
|
|
445
|
+
key={tableKey}
|
|
446
|
+
tableKey={tableKey}
|
|
447
|
+
data={data}
|
|
448
|
+
tableBodyRef={tableBodyRef}
|
|
449
|
+
dataTheme={dataTheme}
|
|
450
|
+
wordWrap={wordWrap}
|
|
451
|
+
autoHeight={autoHeight}
|
|
452
|
+
sortColumn={sortColumn}
|
|
453
|
+
style={{ position: 'relative' }}
|
|
454
|
+
sortType={sortType}
|
|
455
|
+
onSortColumn={handleSortColumn}
|
|
456
|
+
onRowClick={onRowClick}
|
|
457
|
+
tableBodyHeight={tableBodyHeight}
|
|
458
|
+
cellBordered={cellBordered}
|
|
459
|
+
bordered={bordered}
|
|
460
|
+
renderEmpty={(info: React.ReactNode) =>
|
|
461
|
+
renderEmpty ? (
|
|
462
|
+
renderEmpty(info)
|
|
463
|
+
) : (
|
|
464
|
+
<NoData title={emptyTitle ?? 'No Data Found'} subtitle={emptySubTitle} />
|
|
465
|
+
)
|
|
466
|
+
}
|
|
467
|
+
columns={columns}
|
|
468
|
+
minHeight={minHeight}
|
|
469
|
+
headerHeight={headerHeight}
|
|
470
|
+
rowExpandedHeight={rowExpandedHeight}
|
|
471
|
+
loading={isLoading ?? loading}
|
|
472
|
+
showHeader
|
|
473
|
+
defaultChecked
|
|
474
|
+
expandedRowKeys={expandedRowKeys}
|
|
475
|
+
onExpandChange={onExpandChange}
|
|
476
|
+
rowKey={dataRowKey ?? 'id'}
|
|
477
|
+
defaultExpandAllRows={defaultExpandAllRows}
|
|
478
|
+
shouldUpdateScroll={shouldUpdateScroll}
|
|
479
|
+
renderRowExpanded={rowData => {
|
|
480
|
+
return handleRowExpanded?.(rowData);
|
|
481
|
+
}}
|
|
482
|
+
>
|
|
483
|
+
{rowExpand && (
|
|
484
|
+
<Column width={70} align="center" fixed="left">
|
|
485
|
+
<HeaderCell
|
|
486
|
+
verticalAlign={findGrouped() ? 'middle' : undefined}
|
|
487
|
+
className={` ${classes.headerlClass}`}
|
|
488
|
+
renderSortIcon={renderSortIcon}
|
|
489
|
+
>
|
|
490
|
+
#
|
|
491
|
+
</HeaderCell>
|
|
492
|
+
<ExpandCell
|
|
493
|
+
dataKey={dataRowKey}
|
|
494
|
+
expandedRowKeys={expandedRowKeys}
|
|
495
|
+
onChange={handleExpanded}
|
|
496
|
+
/>
|
|
497
|
+
</Column>
|
|
498
|
+
)}
|
|
499
|
+
{selection && (
|
|
500
|
+
<Column width={50} align="center" fixed="left">
|
|
501
|
+
<HeaderCell
|
|
502
|
+
style={{ padding: 0 }}
|
|
503
|
+
verticalAlign={findGrouped() ? 'middle' : undefined}
|
|
504
|
+
dataTheme={dataTheme}
|
|
505
|
+
renderSortIcon={renderSortIcon}
|
|
506
|
+
className={`qbs-checkbox-border-none ${classes.headerlClass}`}
|
|
507
|
+
>
|
|
508
|
+
<div
|
|
509
|
+
style={{ lineHeight: CHECKBOX_LINE_HEIGHT }}
|
|
510
|
+
className={`qbs-table-checkbox ${classes.selectionCell}`}
|
|
511
|
+
>
|
|
512
|
+
<input
|
|
513
|
+
type="checkbox"
|
|
514
|
+
onChange={handleCheckAll}
|
|
515
|
+
id={'checkbox-all'}
|
|
516
|
+
className={`qbs-table-checkbox-input ${classes.tableCheckBoxClass}`}
|
|
517
|
+
checked={data?.length > 0 && data.every(item => checkedKeys?.includes(item.id))}
|
|
518
|
+
/>
|
|
519
|
+
<label htmlFor={'checkbox-all'}>
|
|
520
|
+
<svg
|
|
521
|
+
width="8"
|
|
522
|
+
height="6"
|
|
523
|
+
viewBox="0 0 8 6"
|
|
524
|
+
fill="none"
|
|
525
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
526
|
+
>
|
|
527
|
+
<path
|
|
528
|
+
d="M0 3.21739L2.89883 6L8 1.06994L6.89494 0L2.89883 3.86768L1.09728 2.14745L0 3.21739Z"
|
|
529
|
+
fill="white"
|
|
530
|
+
/>
|
|
531
|
+
</svg>
|
|
532
|
+
</label>
|
|
533
|
+
</div>
|
|
534
|
+
</HeaderCell>
|
|
535
|
+
<CheckCell
|
|
536
|
+
dataKey="id"
|
|
537
|
+
checkedKeys={checkedKeys}
|
|
538
|
+
className={`${classes.tableCheckBoxClass}`}
|
|
539
|
+
onChange={handleCheck}
|
|
540
|
+
dataTheme={dataTheme}
|
|
541
|
+
/>
|
|
542
|
+
</Column>
|
|
543
|
+
)}
|
|
544
|
+
{customRowStatus && Object.keys(customRowStatus)?.length > 0 && (
|
|
545
|
+
<Column width={50} align="center" fixed="left">
|
|
546
|
+
<HeaderCell
|
|
547
|
+
verticalAlign={findGrouped() ? 'middle' : undefined}
|
|
548
|
+
className={` ${classes.headerlClass}`}
|
|
549
|
+
renderSortIcon={renderSortIcon}
|
|
550
|
+
>
|
|
551
|
+
{' '}
|
|
552
|
+
</HeaderCell>
|
|
553
|
+
<CustomRowStatus
|
|
554
|
+
getIcon={customRowStatus.getIcon}
|
|
555
|
+
dataKey={customRowStatus.field}
|
|
556
|
+
rowClick={customRowStatus.onClick}
|
|
557
|
+
path={customRowStatus.getPath}
|
|
558
|
+
link={customRowStatus.link}
|
|
559
|
+
getToolTip={customRowStatus.getToolTip}
|
|
560
|
+
/>
|
|
561
|
+
</Column>
|
|
562
|
+
)}
|
|
563
|
+
{columnsRendered}
|
|
564
|
+
{!actionProps ||
|
|
565
|
+
(actionProps?.length === 0 && columnToggle && (
|
|
566
|
+
<Column width={40} fixed="right">
|
|
567
|
+
<HeaderCell
|
|
568
|
+
verticalAlign={findGrouped() ? 'middle' : undefined}
|
|
569
|
+
className={` ${classes.headerlClass}`}
|
|
570
|
+
dataTheme={dataTheme}
|
|
571
|
+
renderSortIcon={renderSortIcon}
|
|
572
|
+
>
|
|
573
|
+
<ColumToggle
|
|
574
|
+
columns={columns}
|
|
575
|
+
onToggle={handleToggle}
|
|
576
|
+
onReorder={onReorder}
|
|
577
|
+
isOpen={isOpen}
|
|
578
|
+
tableHeight={height}
|
|
579
|
+
setIsOpen={setIsOpen}
|
|
580
|
+
handleResetColumns={handleResetColumns}
|
|
581
|
+
handleColumnToggle={handleColumnToggle}
|
|
582
|
+
/>
|
|
583
|
+
</HeaderCell>
|
|
584
|
+
<Cell />
|
|
585
|
+
</Column>
|
|
586
|
+
))}
|
|
587
|
+
{actionProps && actionProps?.length > 0 && (
|
|
588
|
+
<Column width={40} fixed="right">
|
|
589
|
+
<HeaderCell
|
|
590
|
+
verticalAlign={findGrouped() ? 'middle' : undefined}
|
|
591
|
+
className={` ${classes.headerlClass}`}
|
|
592
|
+
dataTheme={dataTheme}
|
|
593
|
+
renderSortIcon={renderSortIcon}
|
|
594
|
+
>
|
|
595
|
+
{!columnToggle ? (
|
|
596
|
+
<SettingsIcon />
|
|
597
|
+
) : (
|
|
598
|
+
<ColumToggle
|
|
599
|
+
columns={columns}
|
|
600
|
+
onToggle={handleToggle}
|
|
601
|
+
tableHeight={height}
|
|
602
|
+
onReorder={onReorder}
|
|
603
|
+
isOpen={isOpen}
|
|
604
|
+
setIsOpen={setIsOpen}
|
|
605
|
+
handleResetColumns={handleResetColumns}
|
|
606
|
+
handleColumnToggle={handleColumnToggle}
|
|
607
|
+
/>
|
|
608
|
+
)}
|
|
609
|
+
</HeaderCell>
|
|
610
|
+
<ActionCell
|
|
611
|
+
tableBodyRef={tableBodyRef}
|
|
612
|
+
actionProps={actionProps}
|
|
613
|
+
className={`${classes.cellClass} ${classes.actionCellClass}`}
|
|
614
|
+
handleMenuActions={handleMenuActions}
|
|
615
|
+
dataTheme={dataTheme}
|
|
616
|
+
/>
|
|
617
|
+
</Column>
|
|
618
|
+
)}
|
|
619
|
+
</Table>
|
|
620
|
+
|
|
621
|
+
<div>
|
|
622
|
+
{pagination && data?.length > 0 && <Pagination paginationProps={paginationProps} />}
|
|
623
|
+
</div>
|
|
624
|
+
</div>
|
|
625
|
+
</div>
|
|
626
|
+
);
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
export default QbsTable;
|
package/src/qbsTable/Toolbar.tsx
CHANGED
|
@@ -4,6 +4,8 @@ import { QbsTableToolbarProps } from './commontypes';
|
|
|
4
4
|
import debounce from './utilities/debounce';
|
|
5
5
|
import SearchInput from './utilities/SearchInput';
|
|
6
6
|
import { getRowDisplayRange } from './utilities/tablecalc';
|
|
7
|
+
import TooltipComponent from './utilities/ToolTip';
|
|
8
|
+
import { CardIcon, TableIcon } from './utilities/icons';
|
|
7
9
|
|
|
8
10
|
const ToolBar: React.FC<QbsTableToolbarProps> = ({
|
|
9
11
|
pagination,
|
|
@@ -21,7 +23,10 @@ const ToolBar: React.FC<QbsTableToolbarProps> = ({
|
|
|
21
23
|
checkedKeys,
|
|
22
24
|
onSelect,
|
|
23
25
|
dataLength,
|
|
24
|
-
searchPlaceholder
|
|
26
|
+
searchPlaceholder,
|
|
27
|
+
tableViewToggle,
|
|
28
|
+
setTableViewToggle,
|
|
29
|
+
enableTableToggle = false
|
|
25
30
|
}) => {
|
|
26
31
|
const debouncedOnSearch = useCallback(debounce(onSearch ?? (() => {}), 1000), [onSearch]);
|
|
27
32
|
const [searchParam, setSearchParam] = useState<string | undefined>(searchValue);
|
|
@@ -71,7 +76,22 @@ const ToolBar: React.FC<QbsTableToolbarProps> = ({
|
|
|
71
76
|
</div>
|
|
72
77
|
</div>
|
|
73
78
|
|
|
74
|
-
<div className="end-container">
|
|
79
|
+
<div className="end-container">
|
|
80
|
+
{tableHeaderActions}
|
|
81
|
+
<div
|
|
82
|
+
className=" pr-1 cursor-pointer"
|
|
83
|
+
onClick={() => setTableViewToggle?.(!tableViewToggle)}
|
|
84
|
+
>
|
|
85
|
+
{!enableTableToggle && (
|
|
86
|
+
<TooltipComponent
|
|
87
|
+
enabled
|
|
88
|
+
title={tableViewToggle ? 'Switch to Card View' : 'Switch to Table View'}
|
|
89
|
+
>
|
|
90
|
+
{!tableViewToggle ? <CardIcon /> : <TableIcon />}
|
|
91
|
+
</TooltipComponent>
|
|
92
|
+
)}
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
75
95
|
</div>
|
|
76
96
|
{advancefilter && <div className="sub-qbs-table-toolbar">{advancefilter}</div>}
|
|
77
97
|
{((pagination && dataLength > 0) || (checkedKeys && checkedKeys?.length > 0)) && (
|
|
@@ -46,6 +46,9 @@ export interface ActionProps {
|
|
|
46
46
|
toolTip?: string;
|
|
47
47
|
hidden?: boolean;
|
|
48
48
|
hide?: (data: any, index?: number) => boolean;
|
|
49
|
+
isWarning?: boolean;
|
|
50
|
+
label?: string;
|
|
51
|
+
iconName?: string;
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
export interface QbsTableProps {
|
|
@@ -119,6 +122,8 @@ export interface QbsTableProps {
|
|
|
119
122
|
renderEmpty?: (info: React.ReactNode) => React.ReactNode;
|
|
120
123
|
emptySubTitle?: string;
|
|
121
124
|
emptyTitle?: string;
|
|
125
|
+
enableTableToggle?: boolean;
|
|
126
|
+
tableView?: boolean;
|
|
122
127
|
}
|
|
123
128
|
|
|
124
129
|
export interface QbsTableToolbarProps {
|
|
@@ -144,6 +149,10 @@ export interface QbsTableToolbarProps {
|
|
|
144
149
|
dataLength: number;
|
|
145
150
|
headerHeight?: number;
|
|
146
151
|
searchPlaceholder?: string;
|
|
152
|
+
tableView?: boolean;
|
|
153
|
+
enableTableToggle?: boolean;
|
|
154
|
+
tableViewToggle?: boolean;
|
|
155
|
+
setTableViewToggle?: (value: boolean) => void;
|
|
147
156
|
selectedRowActions?: {
|
|
148
157
|
actionTitle?: string;
|
|
149
158
|
action: (checked: (number | string)[]) => void;
|