es-grid-template 0.0.8 → 0.0.13
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/LICENSE +21 -19
- package/es/{CheckboxFilter.js → grid-component/CheckboxFilter.js} +0 -1
- package/es/{ColumnsChoose.js → grid-component/ColumnsChoose.js} +1 -1
- package/es/grid-component/EditableCell.d.ts +19 -0
- package/es/grid-component/EditableCell.js +842 -0
- package/es/{FilterSearch.js → grid-component/FilterSearch.js} +1 -1
- package/es/grid-component/GridStyle.d.ts +4 -0
- package/es/grid-component/GridStyle.js +5 -0
- package/es/{InternalTable.d.ts → grid-component/InternalTable.d.ts} +1 -2
- package/es/grid-component/InternalTable.js +283 -0
- package/es/{LoadingSpinner.js → grid-component/LoadingSpinner.js} +1 -1
- package/es/grid-component/Message/Message.d.ts +2 -0
- package/es/grid-component/Message/Message.js +16 -0
- package/es/grid-component/Message/index.d.ts +1 -0
- package/es/grid-component/Message/index.js +1 -0
- package/{lib → es/grid-component}/TableGrid.d.ts +2 -2
- package/es/grid-component/TableGrid.js +375 -0
- package/es/grid-component/async-table-select/index.d.ts +9 -0
- package/es/grid-component/async-table-select/index.js +37 -0
- package/{lib → es/grid-component}/hooks/constant.d.ts +14 -0
- package/es/{hooks → grid-component/hooks}/constant.js +16 -1
- package/es/grid-component/hooks/useColumns/index.d.ts +6 -0
- package/es/grid-component/hooks/useColumns/index.js +422 -0
- package/es/grid-component/hooks/utils.d.ts +35 -0
- package/es/{hooks → grid-component/hooks}/utils.js +124 -16
- package/es/grid-component/index.d.ts +2 -0
- package/es/grid-component/index.js +2 -0
- package/es/grid-component/rc-table/Grid.d.ts +8 -0
- package/es/grid-component/rc-table/Grid.js +99 -0
- package/es/grid-component/rc-table/GridEdit.d.ts +9 -0
- package/es/grid-component/rc-table/GridEdit.js +706 -0
- package/es/grid-component/type.d.ts +225 -0
- package/es/grid-component/useContext.d.ts +27 -0
- package/es/grid-component/useContext.js +4 -0
- package/es/index.d.ts +1 -2
- package/es/index.js +2 -2
- package/es/table-grid/styles.scss +551 -0
- package/lib/{CheckboxFilter.js → grid-component/CheckboxFilter.js} +0 -1
- package/lib/{ColumnsChoose.js → grid-component/ColumnsChoose.js} +1 -1
- package/lib/grid-component/EditableCell.d.ts +19 -0
- package/lib/grid-component/EditableCell.js +844 -0
- package/lib/{FilterSearch.js → grid-component/FilterSearch.js} +1 -1
- package/lib/grid-component/GridStyle.d.ts +4 -0
- package/lib/grid-component/GridStyle.js +12 -0
- package/lib/{InternalTable.d.ts → grid-component/InternalTable.d.ts} +1 -2
- package/lib/grid-component/InternalTable.js +292 -0
- package/lib/{LoadingSpinner.js → grid-component/LoadingSpinner.js} +1 -1
- package/lib/grid-component/Message/Message.d.ts +2 -0
- package/lib/grid-component/Message/Message.js +25 -0
- package/lib/grid-component/Message/index.d.ts +1 -0
- package/lib/grid-component/Message/index.js +16 -0
- package/{es → lib/grid-component}/TableGrid.d.ts +2 -2
- package/lib/grid-component/TableGrid.js +382 -0
- package/lib/grid-component/async-table-select/index.d.ts +9 -0
- package/lib/grid-component/async-table-select/index.js +46 -0
- package/{es → lib/grid-component}/hooks/constant.d.ts +14 -0
- package/lib/{hooks → grid-component/hooks}/constant.js +17 -2
- package/lib/grid-component/hooks/useColumns/index.d.ts +6 -0
- package/lib/grid-component/hooks/useColumns/index.js +435 -0
- package/lib/grid-component/hooks/utils.d.ts +35 -0
- package/lib/{hooks → grid-component/hooks}/utils.js +140 -19
- package/lib/grid-component/index.d.ts +2 -0
- package/lib/grid-component/index.js +9 -0
- package/lib/grid-component/rc-table/Grid.d.ts +8 -0
- package/lib/grid-component/rc-table/Grid.js +108 -0
- package/lib/grid-component/rc-table/GridEdit.d.ts +9 -0
- package/lib/grid-component/rc-table/GridEdit.js +715 -0
- package/lib/grid-component/type.d.ts +225 -0
- package/lib/grid-component/useContext.d.ts +27 -0
- package/lib/grid-component/useContext.js +10 -0
- package/lib/index.d.ts +1 -2
- package/lib/index.js +7 -3
- package/lib/table-grid/styles.scss +551 -0
- package/package.json +15 -6
- package/es/InternalTable.js +0 -185
- package/es/TableGrid.js +0 -1055
- package/es/hooks/useColumns/index.d.ts +0 -2
- package/es/hooks/useColumns/index.js +0 -25
- package/es/hooks/utils.d.ts +0 -19
- package/es/styles.scss +0 -296
- package/es/type.d.ts +0 -100
- package/lib/InternalTable.js +0 -194
- package/lib/TableGrid.js +0 -1063
- package/lib/hooks/useColumns/index.d.ts +0 -2
- package/lib/hooks/useColumns/index.js +0 -31
- package/lib/hooks/utils.d.ts +0 -19
- package/lib/styles.scss +0 -296
- package/lib/type.d.ts +0 -100
- /package/es/{CheckboxFilter.d.ts → grid-component/CheckboxFilter.d.ts} +0 -0
- /package/es/{ColumnsChoose.d.ts → grid-component/ColumnsChoose.d.ts} +0 -0
- /package/es/{ContextMenu.d.ts → grid-component/ContextMenu.d.ts} +0 -0
- /package/es/{ContextMenu.js → grid-component/ContextMenu.js} +0 -0
- /package/es/{FilterSearch.d.ts → grid-component/FilterSearch.d.ts} +0 -0
- /package/es/{LoadingSpinner.d.ts → grid-component/LoadingSpinner.d.ts} +0 -0
- /package/es/{hooks → grid-component/hooks}/index.d.ts +0 -0
- /package/es/{hooks → grid-component/hooks}/index.js +0 -0
- /package/es/{hooks → grid-component/hooks}/useIsOverflow.d.ts +0 -0
- /package/es/{hooks → grid-component/hooks}/useIsOverflow.js +0 -0
- /package/es/{hooks → grid-component/hooks}/useOnClickOutside.d.ts +0 -0
- /package/es/{hooks → grid-component/hooks}/useOnClickOutside.js +0 -0
- /package/es/{type.js → grid-component/type.js} +0 -0
- /package/lib/{CheckboxFilter.d.ts → grid-component/CheckboxFilter.d.ts} +0 -0
- /package/lib/{ColumnsChoose.d.ts → grid-component/ColumnsChoose.d.ts} +0 -0
- /package/lib/{ContextMenu.d.ts → grid-component/ContextMenu.d.ts} +0 -0
- /package/lib/{ContextMenu.js → grid-component/ContextMenu.js} +0 -0
- /package/lib/{FilterSearch.d.ts → grid-component/FilterSearch.d.ts} +0 -0
- /package/lib/{LoadingSpinner.d.ts → grid-component/LoadingSpinner.d.ts} +0 -0
- /package/lib/{hooks → grid-component/hooks}/index.d.ts +0 -0
- /package/lib/{hooks → grid-component/hooks}/index.js +0 -0
- /package/lib/{hooks → grid-component/hooks}/useIsOverflow.d.ts +0 -0
- /package/lib/{hooks → grid-component/hooks}/useIsOverflow.js +0 -0
- /package/lib/{hooks → grid-component/hooks}/useOnClickOutside.d.ts +0 -0
- /package/lib/{hooks → grid-component/hooks}/useOnClickOutside.js +0 -0
- /package/lib/{type.js → grid-component/type.js} +0 -0
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
// import * as React from 'react'
|
|
2
|
+
|
|
3
|
+
import { checkDecimalSeparator, checkThousandSeparator, convertDateToDayjs, convertDayjsToDate, getDatepickerFormat, getDateString, getTypeFilter, isColor, isEmpty } from "../utils";
|
|
4
|
+
import { NumericFormat, numericFormatter } from "react-numeric-component";
|
|
5
|
+
import dayjs from "dayjs";
|
|
6
|
+
import moment from "moment/moment";
|
|
7
|
+
import React, { Fragment } from "react";
|
|
8
|
+
import { DatePicker, Input, Select } from "rc-master-ui";
|
|
9
|
+
import CheckboxFilter from "../../CheckboxFilter";
|
|
10
|
+
const {
|
|
11
|
+
RangePicker
|
|
12
|
+
} = DatePicker;
|
|
13
|
+
export function flatColumns(columns, parentKey = 'key') {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
return columns.filter(column => column && typeof column === 'object').reduce((list, column, index) => {
|
|
16
|
+
const {
|
|
17
|
+
fixed
|
|
18
|
+
} = column;
|
|
19
|
+
// Convert `fixed='true'` to `fixed='left'` instead
|
|
20
|
+
const parsedFixed = fixed === true ? 'left' : fixed;
|
|
21
|
+
const mergedKey = `${parentKey}-${index}`;
|
|
22
|
+
const subColumns = column.children;
|
|
23
|
+
if (subColumns && subColumns.length > 0) {
|
|
24
|
+
return [...list, ...flatColumns(subColumns, mergedKey).map(subColum => ({
|
|
25
|
+
fixed: parsedFixed,
|
|
26
|
+
...subColum
|
|
27
|
+
}))];
|
|
28
|
+
}
|
|
29
|
+
return [...list, {
|
|
30
|
+
key: mergedKey,
|
|
31
|
+
...column,
|
|
32
|
+
fixed: parsedFixed
|
|
33
|
+
}];
|
|
34
|
+
}, []);
|
|
35
|
+
}
|
|
36
|
+
export const getValueCell = (column, value, format) => {
|
|
37
|
+
switch (column?.type) {
|
|
38
|
+
case 'number':
|
|
39
|
+
const thousandSeparator = column?.format?.thousandSeparator ? column?.format?.thousandSeparator : format?.thousandSeparator;
|
|
40
|
+
const decimalSeparator = column?.format?.decimalSeparator ? column?.format?.decimalSeparator : format?.decimalSeparator;
|
|
41
|
+
const dec = column?.format?.decimalScale || column?.format?.decimalScale === 0 ? column?.format?.decimalScale : format?.decimalScale;
|
|
42
|
+
const content = !isEmpty(value) ? dec || dec === 0 ? parseFloat(Number(value).toFixed(dec)).toString() : value.toString() : '0';
|
|
43
|
+
const numericFormatProps = {
|
|
44
|
+
thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
|
|
45
|
+
decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
|
|
46
|
+
allowNegative: (column?.format?.allowNegative ? column?.format?.allowNegative : format?.allowNegative) ?? true,
|
|
47
|
+
prefix: column?.format?.prefix ? column?.format?.prefix : format?.prefix,
|
|
48
|
+
suffix: column?.format?.suffix ? column?.format?.suffix : format?.suffix,
|
|
49
|
+
decimalScale: column?.format?.decimalScale || column?.format?.decimalScale === 0 ? column?.format?.decimalScale : format?.decimalScale,
|
|
50
|
+
fixedDecimalScale: (column?.format?.fixedDecimalScale ? column?.format?.fixedDecimalScale : format?.fixedDecimalScale) ?? false
|
|
51
|
+
};
|
|
52
|
+
return !isEmpty(content) ? numericFormatter(content, numericFormatProps) : '';
|
|
53
|
+
case 'date':
|
|
54
|
+
return value ? dayjs(value).format(column?.format?.dateFormat ?? format?.dateFormat ?? 'DD/MM/YYYY') : '';
|
|
55
|
+
case 'time':
|
|
56
|
+
return value ? value : '';
|
|
57
|
+
case 'year':
|
|
58
|
+
const year = value ? moment(value).format('yyyy') : '';
|
|
59
|
+
return /*#__PURE__*/React.createElement(Fragment, null, year);
|
|
60
|
+
case 'datetime':
|
|
61
|
+
return value ? moment(value).format(column?.format?.datetimeFormat ?? format?.datetimeFormat ?? 'DD/MM/YYYY HH:mm') : '';
|
|
62
|
+
case 'boolean':
|
|
63
|
+
return value ? 'true' : 'false';
|
|
64
|
+
case 'color':
|
|
65
|
+
return /*#__PURE__*/React.createElement(Fragment, null, isColor(value) ? /*#__PURE__*/React.createElement("div", {
|
|
66
|
+
className: 'w-100 h-100',
|
|
67
|
+
style: {
|
|
68
|
+
backgroundColor: value,
|
|
69
|
+
border: '1px solid #f0f0f0'
|
|
70
|
+
}
|
|
71
|
+
}) : '');
|
|
72
|
+
case 'checkbox':
|
|
73
|
+
return /*#__PURE__*/React.createElement(Input, {
|
|
74
|
+
checked: !!content,
|
|
75
|
+
readOnly: true,
|
|
76
|
+
type: "checkbox"
|
|
77
|
+
});
|
|
78
|
+
case 'file':
|
|
79
|
+
const nameFile = typeof value === 'object' && !Array.isArray(value) ? value.name : Array.isArray(value) ? value.map(it => typeof it === 'object' ? it.name : it).filter(Boolean).join(", ") : '';
|
|
80
|
+
return value ? nameFile : '';
|
|
81
|
+
default:
|
|
82
|
+
if (Array.isArray(value)) {
|
|
83
|
+
return value.join(', ');
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
export const renderContent = (column, value, record, index, format) => {
|
|
89
|
+
const cellValue = value instanceof Date ? getDateString(column, value) : value;
|
|
90
|
+
const content = getValueCell(column, cellValue, format);
|
|
91
|
+
return /*#__PURE__*/React.createElement(Fragment, null, column?.template ? typeof column.template === "function" ? column.template(value, record, index) : column.template : content);
|
|
92
|
+
};
|
|
93
|
+
export const renderFilter = (column, selectedKeys, setSelectedKeys, confirm, visible, searchValue, setSearchValue, dataSourceFilter, buddhistLocale) => {
|
|
94
|
+
const type = getTypeFilter(column);
|
|
95
|
+
const dateFormat = getDatepickerFormat(column?.typeFilter ?? column?.type, column) ?? 'DD/MM/YYYY';
|
|
96
|
+
const dateRangeFormat = getDatepickerFormat(column?.type, column) ?? 'DD/MM/YYYY';
|
|
97
|
+
const find = dataSourceFilter?.find(it => it.key === column?.key);
|
|
98
|
+
const options = find ? find.data : [];
|
|
99
|
+
switch (type) {
|
|
100
|
+
case 'Number':
|
|
101
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
102
|
+
className: 'mb-1'
|
|
103
|
+
}, /*#__PURE__*/React.createElement(NumericFormat, {
|
|
104
|
+
value: selectedKeys[0]
|
|
105
|
+
// thousandSeparator={checkThousandSeparator(thousandSeparator, decimalSeparator)}
|
|
106
|
+
// decimalSeparator={checkDecimalSeparator(thousandSeparator, decimalSeparator)}
|
|
107
|
+
// allowNegative={col.format && col.format.allowNegative === true}
|
|
108
|
+
,
|
|
109
|
+
allowNegative: true,
|
|
110
|
+
customInput: Input,
|
|
111
|
+
className: ' rounded-0 input-element form-control',
|
|
112
|
+
onValueChange: values => {
|
|
113
|
+
// onChangeValueFilter(type, values.floatValue)
|
|
114
|
+
setSelectedKeys(values.floatValue || values.floatValue === 0 ? [values.floatValue] : []);
|
|
115
|
+
}
|
|
116
|
+
}))));
|
|
117
|
+
case 'NumberRange':
|
|
118
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
119
|
+
className: 'mb-1 d-flex flex-column gap-1'
|
|
120
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
121
|
+
style: {
|
|
122
|
+
marginBottom: 8
|
|
123
|
+
}
|
|
124
|
+
}, /*#__PURE__*/React.createElement(NumericFormat, {
|
|
125
|
+
value: selectedKeys[0]
|
|
126
|
+
// thousandSeparator={checkThousandSeparator(thousandSeparator, decimalSeparator)}
|
|
127
|
+
// decimalSeparator={checkDecimalSeparator(thousandSeparator, decimalSeparator)}
|
|
128
|
+
,
|
|
129
|
+
allowNegative: true,
|
|
130
|
+
customInput: Input,
|
|
131
|
+
className: ' rounded-0 input-element form-control'
|
|
132
|
+
// onValueChange={(values: any) => {
|
|
133
|
+
// onChangeValueFilter(type, values.floatValue, 'min')
|
|
134
|
+
// }}
|
|
135
|
+
,
|
|
136
|
+
placeholder: 'Min',
|
|
137
|
+
autoFocus: true
|
|
138
|
+
})), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(NumericFormat, {
|
|
139
|
+
value: selectedKeys[1]
|
|
140
|
+
// thousandSeparator={checkThousandSeparator(thousandSeparator, decimalSeparator)}
|
|
141
|
+
// decimalSeparator={checkDecimalSeparator(thousandSeparator, decimalSeparator)}
|
|
142
|
+
,
|
|
143
|
+
allowNegative: true,
|
|
144
|
+
customInput: Input,
|
|
145
|
+
className: ' rounded-0 input-element form-control',
|
|
146
|
+
onValueChange: () => {
|
|
147
|
+
// onChangeValueFilter(type, values.floatValue, 'max')
|
|
148
|
+
},
|
|
149
|
+
placeholder: 'Max'
|
|
150
|
+
})))));
|
|
151
|
+
case 'Date':
|
|
152
|
+
const dateValue = selectedKeys[0] ? convertDateToDayjs(new Date(selectedKeys[0]), dateFormat) : null;
|
|
153
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
154
|
+
className: 'mb-1'
|
|
155
|
+
}, /*#__PURE__*/React.createElement(DatePicker, {
|
|
156
|
+
format: {
|
|
157
|
+
format: dateFormat,
|
|
158
|
+
type: 'mask'
|
|
159
|
+
},
|
|
160
|
+
locale: buddhistLocale,
|
|
161
|
+
style: {
|
|
162
|
+
width: '100%',
|
|
163
|
+
height: '100%'
|
|
164
|
+
},
|
|
165
|
+
value: dateValue,
|
|
166
|
+
defaultValue: dateValue,
|
|
167
|
+
placeholder: column?.placeholder,
|
|
168
|
+
onChange: (date, dateString) => {
|
|
169
|
+
const newDateValue = dateString ? moment(convertDayjsToDate(dateString, dateFormat)).format() : null;
|
|
170
|
+
setSelectedKeys(newDateValue ? [newDateValue] : []);
|
|
171
|
+
}
|
|
172
|
+
}))));
|
|
173
|
+
case 'DateRange':
|
|
174
|
+
const dateRangeValue = [selectedKeys[0] ? convertDateToDayjs(new Date(selectedKeys[0]), dateRangeFormat) : '', selectedKeys[1] ? convertDateToDayjs(new Date(selectedKeys[1]), dateRangeFormat) : ''];
|
|
175
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
176
|
+
className: 'mb-1'
|
|
177
|
+
}, /*#__PURE__*/React.createElement(RangePicker, {
|
|
178
|
+
format: {
|
|
179
|
+
format: dateRangeFormat,
|
|
180
|
+
type: 'mask'
|
|
181
|
+
}
|
|
182
|
+
// defaultValue={dateRangeValue}
|
|
183
|
+
,
|
|
184
|
+
value: dateRangeValue,
|
|
185
|
+
placeholder: ['Ngày bắt đầu', 'Ngày kết thúc'],
|
|
186
|
+
popupStyle: {
|
|
187
|
+
zIndex: 9999
|
|
188
|
+
},
|
|
189
|
+
onChange: (value, dateString) => {
|
|
190
|
+
const newDateRangeValue = dateString[0] ? [dateString[0] ? moment(convertDayjsToDate(dateString[0], dateRangeFormat)).format() : '', dateString[1] ? moment(convertDayjsToDate(dateString[1], dateRangeFormat)).format() : ''] : '';
|
|
191
|
+
|
|
192
|
+
// setSelectedKeys(newDateValue ? [newDateValue] : [])
|
|
193
|
+
setSelectedKeys(newDateRangeValue);
|
|
194
|
+
},
|
|
195
|
+
style: {
|
|
196
|
+
width: '100%'
|
|
197
|
+
}
|
|
198
|
+
// popupClassName={'adv-popup-container'}
|
|
199
|
+
// getPopupContainer={() => menuRef.current}
|
|
200
|
+
}))));
|
|
201
|
+
case 'Week':
|
|
202
|
+
const weekValue = !isEmpty(selectedKeys[0]) ? dayjs(selectedKeys[0], dateFormat) : null;
|
|
203
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
204
|
+
className: 'mb-1'
|
|
205
|
+
}, /*#__PURE__*/React.createElement(DatePicker, {
|
|
206
|
+
format: {
|
|
207
|
+
format: dateFormat,
|
|
208
|
+
type: 'mask'
|
|
209
|
+
},
|
|
210
|
+
picker: 'week',
|
|
211
|
+
locale: buddhistLocale,
|
|
212
|
+
style: {
|
|
213
|
+
width: '100%',
|
|
214
|
+
height: '100%'
|
|
215
|
+
},
|
|
216
|
+
value: weekValue,
|
|
217
|
+
defaultValue: weekValue,
|
|
218
|
+
placeholder: column?.placeholder,
|
|
219
|
+
onChange: (date, dateString) => {
|
|
220
|
+
const newDateValue = dateString ?? null;
|
|
221
|
+
setSelectedKeys(newDateValue ? [newDateValue] : []);
|
|
222
|
+
}
|
|
223
|
+
}))));
|
|
224
|
+
case 'Month':
|
|
225
|
+
const monthValue = !isEmpty(selectedKeys[0]) ? dayjs(selectedKeys[0], dateFormat) : null;
|
|
226
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
227
|
+
className: 'mb-1'
|
|
228
|
+
}, /*#__PURE__*/React.createElement(DatePicker, {
|
|
229
|
+
format: {
|
|
230
|
+
format: dateFormat,
|
|
231
|
+
type: 'mask'
|
|
232
|
+
},
|
|
233
|
+
picker: 'month',
|
|
234
|
+
locale: buddhistLocale,
|
|
235
|
+
style: {
|
|
236
|
+
width: '100%',
|
|
237
|
+
height: '100%'
|
|
238
|
+
},
|
|
239
|
+
value: monthValue,
|
|
240
|
+
defaultValue: monthValue,
|
|
241
|
+
placeholder: column?.placeholder,
|
|
242
|
+
onChange: (date, dateString) => {
|
|
243
|
+
const newDateValue = dateString ?? null;
|
|
244
|
+
setSelectedKeys(newDateValue ? [newDateValue] : []);
|
|
245
|
+
}
|
|
246
|
+
})));
|
|
247
|
+
|
|
248
|
+
// case 'Quarter':
|
|
249
|
+
//
|
|
250
|
+
// // const monthValue = selectedKeys[0] ? convertDateToDayjs(new Date(selectedKeys[0]), dateFormat) : null
|
|
251
|
+
//
|
|
252
|
+
// const pickerFormat = getDatepickerFormat(getEditType(col) as IEditType, col)
|
|
253
|
+
// const pickerValue = !isEmpty(selectedKeys[0]) ? dayjs(selectedKeys[0], pickerFormat) : null
|
|
254
|
+
//
|
|
255
|
+
// return (
|
|
256
|
+
// <Fragment>
|
|
257
|
+
// <div>
|
|
258
|
+
//
|
|
259
|
+
//
|
|
260
|
+
// <div className={'mb-1'}>
|
|
261
|
+
//
|
|
262
|
+
// <DatePicker
|
|
263
|
+
// format={{
|
|
264
|
+
// format: dateFormat,
|
|
265
|
+
// type: 'mask'
|
|
266
|
+
// }}
|
|
267
|
+
// locale={buddhistLocale}
|
|
268
|
+
// style={{width: '100%', height: '100%'}}
|
|
269
|
+
// value={pickerValue}
|
|
270
|
+
// defaultValue={pickerValue}
|
|
271
|
+
// placeholder={column.placeholder}
|
|
272
|
+
// onChange={(date, dateString) => {
|
|
273
|
+
// const newDateValue = dateString ? moment(convertDayjsToDate(dateString as string, dateFormat)).format() : null
|
|
274
|
+
// setSelectedKeys(newDateValue ? [newDateValue] : [])
|
|
275
|
+
//
|
|
276
|
+
// }}
|
|
277
|
+
//
|
|
278
|
+
// />
|
|
279
|
+
// </div>
|
|
280
|
+
//
|
|
281
|
+
//
|
|
282
|
+
// </div>
|
|
283
|
+
// </Fragment>
|
|
284
|
+
// )
|
|
285
|
+
//
|
|
286
|
+
// case 'Year':
|
|
287
|
+
//
|
|
288
|
+
// // const monthValue = selectedKeys[0] ? convertDateToDayjs(new Date(selectedKeys[0]), dateFormat) : null
|
|
289
|
+
//
|
|
290
|
+
// const pickerFormat = getDatepickerFormat(getEditType(col) as IEditType, col)
|
|
291
|
+
// const pickerValue = !isEmpty(selectedKeys[0]) ? dayjs(selectedKeys[0], pickerFormat) : null
|
|
292
|
+
//
|
|
293
|
+
// return (
|
|
294
|
+
// <Fragment>
|
|
295
|
+
// <div>
|
|
296
|
+
//
|
|
297
|
+
//
|
|
298
|
+
// <div className={'mb-1'}>
|
|
299
|
+
//
|
|
300
|
+
// <DatePicker
|
|
301
|
+
// format={{
|
|
302
|
+
// format: dateFormat,
|
|
303
|
+
// type: 'mask'
|
|
304
|
+
// }}
|
|
305
|
+
// locale={buddhistLocale}
|
|
306
|
+
// style={{width: '100%', height: '100%'}}
|
|
307
|
+
// value={pickerValue}
|
|
308
|
+
// defaultValue={pickerValue}
|
|
309
|
+
// placeholder={column.placeholder}
|
|
310
|
+
// onChange={(date, dateString) => {
|
|
311
|
+
// const newDateValue = dateString ? moment(convertDayjsToDate(dateString as string, dateFormat)).format() : null
|
|
312
|
+
// setSelectedKeys(newDateValue ? [newDateValue] : [])
|
|
313
|
+
//
|
|
314
|
+
// }}
|
|
315
|
+
//
|
|
316
|
+
// />
|
|
317
|
+
// </div>
|
|
318
|
+
//
|
|
319
|
+
//
|
|
320
|
+
// </div>
|
|
321
|
+
// </Fragment>
|
|
322
|
+
// )
|
|
323
|
+
|
|
324
|
+
case 'Dropdown':
|
|
325
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
326
|
+
className: 'mb-1'
|
|
327
|
+
}, /*#__PURE__*/React.createElement(Select
|
|
328
|
+
// options={translateOption(numberOperator, t)}
|
|
329
|
+
, {
|
|
330
|
+
options: options,
|
|
331
|
+
style: {
|
|
332
|
+
width: '100%',
|
|
333
|
+
marginBottom: 8
|
|
334
|
+
},
|
|
335
|
+
value: selectedKeys[0],
|
|
336
|
+
onChange: val => {
|
|
337
|
+
// setOperatorKey(val)
|
|
338
|
+
setSelectedKeys(val ? [val] : []);
|
|
339
|
+
},
|
|
340
|
+
showSearch: true,
|
|
341
|
+
allowClear: true
|
|
342
|
+
}))));
|
|
343
|
+
|
|
344
|
+
// case 'DropTree':
|
|
345
|
+
// return (
|
|
346
|
+
// <Fragment>
|
|
347
|
+
// <div>
|
|
348
|
+
// {col.filterOption && col.filterOption.showOperator === false ? (
|
|
349
|
+
// ''
|
|
350
|
+
// ) : (
|
|
351
|
+
// <div className={'mb-1'}>
|
|
352
|
+
// <Select
|
|
353
|
+
// options={translateOption(numberOperator, t)}
|
|
354
|
+
// // options={t ? numberOperator.map((it: any) => ({...it, label: t(it.label)})) : numberOperator}
|
|
355
|
+
//
|
|
356
|
+
// classNamePrefix='select'
|
|
357
|
+
// className={`react-select`}
|
|
358
|
+
// value={translateOption(numberOperator, t).find(
|
|
359
|
+
// ope => ope.value === (operator ? operator : getDefaultOperator(col))
|
|
360
|
+
// )}
|
|
361
|
+
// onChange={(val: any) => {
|
|
362
|
+
// setCurrentFilter((prevState: any) => ({ ...prevState, operator: val.value }))
|
|
363
|
+
// }}
|
|
364
|
+
// />
|
|
365
|
+
// </div>
|
|
366
|
+
// )}
|
|
367
|
+
//
|
|
368
|
+
// <div className={'mb-1'}>
|
|
369
|
+
// <Input
|
|
370
|
+
// placeholder={'Nhập giá trị'}
|
|
371
|
+
// value={value}
|
|
372
|
+
// onChange={(val: any) => {
|
|
373
|
+
// onChangeValueFilter(type, val.value)
|
|
374
|
+
// }}
|
|
375
|
+
// />
|
|
376
|
+
// </div>
|
|
377
|
+
//
|
|
378
|
+
// <div className={'d-flex justify-content-end'}>
|
|
379
|
+
// <Button color='flat-primary' className={'me-1 be-button'} onClick={(e: any) => handleOnFilter(e)}>
|
|
380
|
+
// {t ? t('Filter') : 'Filter'}
|
|
381
|
+
// </Button>
|
|
382
|
+
// <Button color='flat-secondary' className={'be-button'} onClick={(e: any) => handleClearFilter(e)}>
|
|
383
|
+
// {t ? t('Delete') : 'Delete'}
|
|
384
|
+
// </Button>
|
|
385
|
+
// </div>
|
|
386
|
+
// </div>
|
|
387
|
+
// </Fragment>
|
|
388
|
+
// )
|
|
389
|
+
//
|
|
390
|
+
case 'Checkbox':
|
|
391
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
392
|
+
className: 'mb-1'
|
|
393
|
+
}, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(CheckboxFilter
|
|
394
|
+
// column={column}
|
|
395
|
+
, {
|
|
396
|
+
locale: {
|
|
397
|
+
filterTitle: 'Chọn tất cả',
|
|
398
|
+
filterCheckall: 'Chọn tất cả'
|
|
399
|
+
},
|
|
400
|
+
selectedKeys: selectedKeys,
|
|
401
|
+
onSelect: setSelectedKeys,
|
|
402
|
+
options: options,
|
|
403
|
+
filterMultiple: true,
|
|
404
|
+
open: visible,
|
|
405
|
+
searchValue: searchValue,
|
|
406
|
+
setSearchValue: setSearchValue
|
|
407
|
+
})))));
|
|
408
|
+
case 'Text':
|
|
409
|
+
default:
|
|
410
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
411
|
+
className: 'mb-1'
|
|
412
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
413
|
+
placeholder: `Search ${column?.dataIndex}`,
|
|
414
|
+
value: selectedKeys[0],
|
|
415
|
+
onChange: e => setSelectedKeys(e.target.value ? [e.target.value] : [])
|
|
416
|
+
// onPressEnter={() => handleSearch(selectedKeys as string[], confirm)}
|
|
417
|
+
,
|
|
418
|
+
onPressEnter: () => confirm(),
|
|
419
|
+
allowClear: true
|
|
420
|
+
}))));
|
|
421
|
+
}
|
|
422
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import dayjs from "dayjs";
|
|
3
|
+
import type { EditType, IColumnType, TypeFilter } from "rc-master-ui";
|
|
4
|
+
import type { ColumnEditType, ColumnsType, ColumnTable } from "../type";
|
|
5
|
+
import type { SelectionSettings } from "../type";
|
|
6
|
+
import type { AnyObject } from "../type";
|
|
7
|
+
export declare const newGuid: () => any;
|
|
8
|
+
export declare const sumDataByField: (data: any[], field: string) => any;
|
|
9
|
+
export declare const checkThousandSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
|
|
10
|
+
export declare const checkDecimalSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
|
|
11
|
+
export declare const isEmpty: (d: any) => boolean;
|
|
12
|
+
export declare const isNullOrUndefined: (d: any) => boolean;
|
|
13
|
+
export declare const convertDayjsToDate: (dateString: string, format?: string) => Date;
|
|
14
|
+
export declare const convertDateToDayjs: (date: Date | undefined, format?: string) => dayjs.Dayjs;
|
|
15
|
+
export declare const isNameColor: (strColor: string) => boolean;
|
|
16
|
+
export declare const isColor: (value: string) => boolean;
|
|
17
|
+
export declare const getAllVisibleKeys: (columns: any[]) => any[];
|
|
18
|
+
export declare const getVisibleColumnKeys: (columns: any[]) => string[];
|
|
19
|
+
export declare function getHiddenParentKeys(columns: any[], parentKeys?: string[]): string[];
|
|
20
|
+
export declare const updateColumns: (columns: any[], includes: string[]) => any[];
|
|
21
|
+
export declare const getDatepickerFormat: (type: EditType | TypeFilter | IColumnType, col: ColumnTable<any>) => string;
|
|
22
|
+
export declare const customWeekStartEndFormat: (value: any, weekFormat: string) => string;
|
|
23
|
+
export declare const getTypeFilter: (col: ColumnTable<any>) => TypeFilter;
|
|
24
|
+
export declare const updateArrayByKey: (arr: any[], element: any, key: string) => any[];
|
|
25
|
+
export declare const getDateString: <T>(column: ColumnTable<T>, value: any) => string;
|
|
26
|
+
export declare const getEditType: <T>(column: ColumnEditType<T>, rowData?: any) => EditType | ((rowData?: any) => EditType);
|
|
27
|
+
export declare const isDisable: <T>(column: ColumnEditType<T>, rowData?: any) => boolean;
|
|
28
|
+
export declare const checkFieldKey: (key: string | undefined) => string;
|
|
29
|
+
export declare const convertLabelToTitle: (data: any[]) => any[];
|
|
30
|
+
export declare const convertArrayWithIndent: (inputArray: any[], parentIndent?: number) => any[];
|
|
31
|
+
export declare const getTemplate: (template: any) => React.ReactNode | React.ReactElement;
|
|
32
|
+
export declare const totalFixedWidth: <T>(columns: ColumnsType<T>, type: 'left' | 'right', selectionSettings?: SelectionSettings) => number;
|
|
33
|
+
export declare const isObjEmpty: (obj: any) => boolean;
|
|
34
|
+
export declare const getColumnsVisible: <T>(columns: ColumnsType<T>, index: number) => import("../type").ColumnType<T>[];
|
|
35
|
+
export declare const updateData: <Record_1 = AnyObject>(initData: Record_1[], rows: Record_1[], key: keyof Record_1) => Record_1[];
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
|
+
import moment from "moment/moment";
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
export const newGuid = () => {
|
|
5
|
+
for (let i = 0; i < 20; i++) {
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
// const id = crypto.randomUUID()
|
|
8
|
+
return uuidv4();
|
|
9
|
+
}
|
|
10
|
+
};
|
|
2
11
|
export const sumDataByField = (data, field) => {
|
|
3
12
|
if (data && data.length > 0) {
|
|
4
13
|
return data.reduce((accumulator, currentValue) => {
|
|
@@ -43,16 +52,10 @@ export const checkDecimalSeparator = (thousandSeparator, decimalSeparator) => {
|
|
|
43
52
|
}
|
|
44
53
|
};
|
|
45
54
|
export const isEmpty = d => {
|
|
46
|
-
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
return false;
|
|
55
|
+
return d === null || d === undefined || d === '';
|
|
50
56
|
};
|
|
51
57
|
export const isNullOrUndefined = d => {
|
|
52
|
-
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
return false;
|
|
58
|
+
return d === null || d === undefined;
|
|
56
59
|
};
|
|
57
60
|
export const convertDayjsToDate = (dateString, format) => {
|
|
58
61
|
const dayjsDate = dayjs(dateString, format); // Parse using the provided format
|
|
@@ -101,8 +104,7 @@ export const getAllVisibleKeys = columns => {
|
|
|
101
104
|
export const getVisibleColumnKeys = columns => {
|
|
102
105
|
const allKeys = getAllVisibleKeys(columns);
|
|
103
106
|
const allParentKeys = getHiddenParentKeys(columns);
|
|
104
|
-
|
|
105
|
-
return rs;
|
|
107
|
+
return allKeys.filter(item => !allParentKeys.includes(item));
|
|
106
108
|
};
|
|
107
109
|
export function getHiddenParentKeys(columns, parentKeys = []) {
|
|
108
110
|
const hiddenParents = new Set();
|
|
@@ -133,11 +135,7 @@ export const updateColumns = (columns, includes) => {
|
|
|
133
135
|
newColumn.children = updateColumns(newColumn.children, includes);
|
|
134
136
|
hasVisibleChild = newColumn.children.some(child => !child.hidden);
|
|
135
137
|
}
|
|
136
|
-
|
|
137
|
-
newColumn.hidden = true;
|
|
138
|
-
} else {
|
|
139
|
-
newColumn.hidden = false;
|
|
140
|
-
}
|
|
138
|
+
newColumn.hidden = newColumn.key && !includes.includes(newColumn.key);
|
|
141
139
|
if (newColumn.children && newColumn.children.length > 0) {
|
|
142
140
|
newColumn.hidden = !hasVisibleChild;
|
|
143
141
|
}
|
|
@@ -163,9 +161,12 @@ export const getDatepickerFormat = (type, col) => {
|
|
|
163
161
|
case "time":
|
|
164
162
|
return col.format?.timeFormat ? col.format?.timeFormat : 'HH:mm';
|
|
165
163
|
default:
|
|
166
|
-
return
|
|
164
|
+
return 'DD/MM/YYYY';
|
|
167
165
|
}
|
|
168
166
|
};
|
|
167
|
+
export const customWeekStartEndFormat = (value, weekFormat) => {
|
|
168
|
+
return `${dayjs(value).startOf('week').format(weekFormat)} ~ ${dayjs(value).endOf('week').format(weekFormat)}`;
|
|
169
|
+
};
|
|
169
170
|
export const getTypeFilter = col => {
|
|
170
171
|
if (col?.typeFilter) {
|
|
171
172
|
return col.typeFilter;
|
|
@@ -209,4 +210,111 @@ export const updateArrayByKey = (arr, element, key) => {
|
|
|
209
210
|
} else {
|
|
210
211
|
return [];
|
|
211
212
|
}
|
|
213
|
+
};
|
|
214
|
+
export const getDateString = (column, value) => {
|
|
215
|
+
if (value instanceof Date) {
|
|
216
|
+
return moment(value).format();
|
|
217
|
+
}
|
|
218
|
+
return value;
|
|
219
|
+
};
|
|
220
|
+
export const getEditType = (column, rowData) => {
|
|
221
|
+
if (column && typeof column.editType === 'function') {
|
|
222
|
+
return column.editType(rowData);
|
|
223
|
+
}
|
|
224
|
+
return column.editType;
|
|
225
|
+
};
|
|
226
|
+
export const isDisable = (column, rowData) => {
|
|
227
|
+
if (column && typeof column?.disable === 'function') {
|
|
228
|
+
return column.disable(rowData);
|
|
229
|
+
}
|
|
230
|
+
return !!column?.disable;
|
|
231
|
+
};
|
|
232
|
+
export const checkFieldKey = key => {
|
|
233
|
+
if (key) {
|
|
234
|
+
return key;
|
|
235
|
+
} else {
|
|
236
|
+
return 'value';
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
export const convertLabelToTitle = data => {
|
|
240
|
+
return data.map(item => {
|
|
241
|
+
const {
|
|
242
|
+
label,
|
|
243
|
+
title,
|
|
244
|
+
value,
|
|
245
|
+
...rest
|
|
246
|
+
} = item;
|
|
247
|
+
const newItem = {
|
|
248
|
+
...rest,
|
|
249
|
+
value,
|
|
250
|
+
key: value,
|
|
251
|
+
title: title ? title : label
|
|
252
|
+
};
|
|
253
|
+
if (item.children) {
|
|
254
|
+
newItem.children = convertLabelToTitle(item.children);
|
|
255
|
+
}
|
|
256
|
+
return newItem;
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
export const convertArrayWithIndent = (inputArray, parentIndent = 0) => {
|
|
260
|
+
if (inputArray) {
|
|
261
|
+
return inputArray.map(item => {
|
|
262
|
+
const indent = parentIndent;
|
|
263
|
+
if (item.children && item.children.length > 0) {
|
|
264
|
+
item.children = convertArrayWithIndent(item.children, indent + 1);
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
...item,
|
|
268
|
+
indent,
|
|
269
|
+
rowId: item.rowId ? item.rowId : item.id ? item.id : newGuid()
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
} else {
|
|
273
|
+
return [];
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
export const getTemplate = template => {
|
|
277
|
+
if (template && typeof template === 'function') {
|
|
278
|
+
return template();
|
|
279
|
+
}
|
|
280
|
+
return template;
|
|
281
|
+
};
|
|
282
|
+
export const totalFixedWidth = (columns, type, selectionSettings) => {
|
|
283
|
+
const totalFixedLeftWidth = columns.filter(column => column.fixed === type) // Lọc các cột có fixed
|
|
284
|
+
.reduce((sum, column) => {
|
|
285
|
+
const width = typeof column.width === 'number' ? column.width : parseInt(column.width, 10) || 0; // Chuyển từ chuỗi sang số, nếu không hợp lệ thì lấy 0
|
|
286
|
+
return sum + width;
|
|
287
|
+
}, 0);
|
|
288
|
+
const selectColumnWidth = !selectionSettings?.mode ? 0.0000001 : typeof selectionSettings?.columnWidth === 'number' ? selectionSettings?.columnWidth : parseInt(selectionSettings?.columnWidth, 10) || 50;
|
|
289
|
+
return totalFixedLeftWidth + selectColumnWidth;
|
|
290
|
+
};
|
|
291
|
+
export const isObjEmpty = obj => {
|
|
292
|
+
if (isNullOrUndefined(obj)) {
|
|
293
|
+
return true;
|
|
294
|
+
} else {
|
|
295
|
+
return Object.keys(obj).length === 0;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
export const getColumnsVisible = (columns, index) => {
|
|
299
|
+
const itemsBeforeIndex = columns.slice(0, index);
|
|
300
|
+
const itemsAfterIndex = columns.slice(index);
|
|
301
|
+
itemsAfterIndex.map(it => {
|
|
302
|
+
if (it.hidden !== false) {
|
|
303
|
+
itemsBeforeIndex.push(it);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
return itemsBeforeIndex;
|
|
307
|
+
};
|
|
308
|
+
export const updateData = (initData, rows, key) => {
|
|
309
|
+
const updatedData = initData.map(item => {
|
|
310
|
+
const newData = rows.find(row => row[key] === item[key]);
|
|
311
|
+
return newData ? {
|
|
312
|
+
...item,
|
|
313
|
+
...newData
|
|
314
|
+
} : item;
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
// Thêm các phần tử mới chưa có trong initialData
|
|
318
|
+
const newRows = rows.filter(row => !initData.some(item => item[key] === row[key]));
|
|
319
|
+
return [...updatedData, ...newRows];
|
|
212
320
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { GridTableProps } from "../type";
|
|
3
|
+
type Props<T> = GridTableProps<T> & {
|
|
4
|
+
setColumns?: any;
|
|
5
|
+
tableRef: any;
|
|
6
|
+
};
|
|
7
|
+
declare const Grid: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
|
|
8
|
+
export default Grid;
|