@visns-studio/visns-components 2.5.14 → 2.5.16
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.
|
@@ -153,7 +153,6 @@ const DataGrid = forwardRef(
|
|
|
153
153
|
const data = useCallback(
|
|
154
154
|
(params) => {
|
|
155
155
|
const sqlResult = loadData(params, dSearch, ajaxSetting);
|
|
156
|
-
|
|
157
156
|
if (setFilterData && params.filterValue) {
|
|
158
157
|
setFilterData(params.filterValue);
|
|
159
158
|
}
|
|
@@ -172,6 +171,7 @@ const DataGrid = forwardRef(
|
|
|
172
171
|
const [filterDataSource, setFilterDataSource] = useState([]);
|
|
173
172
|
const [filterValue, setFilterValue] = useState([]);
|
|
174
173
|
const [gridColumns, setGridColumns] = useState([]);
|
|
174
|
+
const gridRef = useRef(null);
|
|
175
175
|
const [limit, setLimit] = useState(0);
|
|
176
176
|
const [search, setSearch] = useState('');
|
|
177
177
|
const [selected, setSelected] = useState({});
|
|
@@ -183,9 +183,18 @@ const DataGrid = forwardRef(
|
|
|
183
183
|
},
|
|
184
184
|
}));
|
|
185
185
|
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
const handleSelectionChange = useCallback((param) => {
|
|
187
|
+
if (param.selected === true) {
|
|
188
|
+
const s = {};
|
|
189
|
+
|
|
190
|
+
param.data.forEach((obj) => {
|
|
191
|
+
s[obj.id] = obj;
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
setSelected(s);
|
|
195
|
+
} else {
|
|
196
|
+
setSelected(param.selected);
|
|
197
|
+
}
|
|
189
198
|
}, []);
|
|
190
199
|
|
|
191
200
|
const handleFilterChange = useCallback((d) => {
|
|
@@ -572,7 +581,9 @@ const DataGrid = forwardRef(
|
|
|
572
581
|
|
|
573
582
|
/** Table Hooks */
|
|
574
583
|
useEffect(() => {
|
|
575
|
-
setRowsSelected
|
|
584
|
+
if (setRowsSelected) {
|
|
585
|
+
setRowsSelected(selected);
|
|
586
|
+
}
|
|
576
587
|
}, [selected]);
|
|
577
588
|
|
|
578
589
|
useEffect(() => {
|
|
@@ -1888,16 +1899,17 @@ const DataGrid = forwardRef(
|
|
|
1888
1899
|
limit={limit}
|
|
1889
1900
|
enableColumnAutosize={false}
|
|
1890
1901
|
enableColumnFilterContextMenu={false}
|
|
1891
|
-
|
|
1902
|
+
handle={(ref) =>
|
|
1903
|
+
(gridRef.current = ref ? ref.current : null)
|
|
1904
|
+
}
|
|
1892
1905
|
headerProps={headerProps}
|
|
1893
1906
|
idProperty="id"
|
|
1894
1907
|
minRowHeight={40}
|
|
1895
|
-
multiSelect={true}
|
|
1896
1908
|
onFilterValueChange={(filterValue) => {
|
|
1897
1909
|
handleFilterChange(filterValue);
|
|
1898
1910
|
}}
|
|
1899
1911
|
onLimitChange={setLimit}
|
|
1900
|
-
onSelectionChange={
|
|
1912
|
+
onSelectionChange={handleSelectionChange}
|
|
1901
1913
|
onSortInfoChange={handleSort}
|
|
1902
1914
|
onRenderRow={onRenderRow}
|
|
1903
1915
|
pagination
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { Outlet } from 'react-router-dom';
|
|
3
3
|
import { toast } from 'react-toastify';
|
|
4
|
+
import CustomFetch from '../Fetch';
|
|
4
5
|
import Table from '../DataGrid';
|
|
5
6
|
import TableFilter from '../TableFilter';
|
|
6
7
|
|
|
@@ -16,6 +17,7 @@ function GenericIndex({ layout = 'full', setting, userProfile }) {
|
|
|
16
17
|
tableSetting,
|
|
17
18
|
tabs,
|
|
18
19
|
} = setting;
|
|
20
|
+
const gridRef = useRef(null);
|
|
19
21
|
|
|
20
22
|
const [config, setConfig] = useState({});
|
|
21
23
|
const [rowsSelected, setRowsSelected] = useState({});
|
|
@@ -28,16 +30,30 @@ function GenericIndex({ layout = 'full', setting, userProfile }) {
|
|
|
28
30
|
return Object.keys(obj).length === 0;
|
|
29
31
|
};
|
|
30
32
|
|
|
31
|
-
const handleCheckboxUpdate = (e) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
const handleCheckboxUpdate = async (e) => {
|
|
34
|
+
try {
|
|
35
|
+
e.preventDefault();
|
|
36
|
+
const { data, method, message, url } = functions.checkboxUpdate;
|
|
37
|
+
|
|
38
|
+
if (isObjectEmpty(rowsSelected)) {
|
|
39
|
+
toast.warning(message.warning);
|
|
40
|
+
} else {
|
|
41
|
+
const res = await CustomFetch(url, method, {
|
|
42
|
+
...data,
|
|
43
|
+
rows: rowsSelected,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
console.info(res);
|
|
47
|
+
|
|
48
|
+
if (res.data.error === '') {
|
|
49
|
+
toast.success(message.success);
|
|
50
|
+
gridRef.current.reload();
|
|
51
|
+
} else {
|
|
52
|
+
toast.error(message.error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error(error);
|
|
41
57
|
}
|
|
42
58
|
};
|
|
43
59
|
|
|
@@ -126,6 +142,7 @@ function GenericIndex({ layout = 'full', setting, userProfile }) {
|
|
|
126
142
|
<div className={`grid__subcontent`}>
|
|
127
143
|
<Table
|
|
128
144
|
{...config}
|
|
145
|
+
ref={gridRef}
|
|
129
146
|
gridHeight={windowHeight * 0.65}
|
|
130
147
|
setConfig={setConfig}
|
|
131
148
|
setTotal={setTotal}
|
|
@@ -150,6 +167,7 @@ function GenericIndex({ layout = 'full', setting, userProfile }) {
|
|
|
150
167
|
<div className={`tabcontent__main`}>
|
|
151
168
|
<Table
|
|
152
169
|
{...config}
|
|
170
|
+
ref={gridRef}
|
|
153
171
|
gridHeight={
|
|
154
172
|
windowHeight * 0.65
|
|
155
173
|
}
|
|
@@ -169,6 +187,7 @@ function GenericIndex({ layout = 'full', setting, userProfile }) {
|
|
|
169
187
|
<div className="grid__full">
|
|
170
188
|
<Table
|
|
171
189
|
{...config}
|
|
190
|
+
ref={gridRef}
|
|
172
191
|
gridHeight={windowHeight * 0.65}
|
|
173
192
|
setConfig={setConfig}
|
|
174
193
|
setTotal={setTotal}
|
package/package.json
CHANGED