es-grid-template 1.8.70 → 1.8.72

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.
Files changed (239) hide show
  1. package/es/grid-component/TempTable.js +2 -1
  2. package/es/group-component/ColumnsChoose.d.ts +13 -0
  3. package/es/group-component/ColumnsChoose.js +211 -0
  4. package/es/group-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
  5. package/es/group-component/ColumnsGroup/ColumnsGroup.js +230 -0
  6. package/es/group-component/ColumnsGroup/index.d.ts +1 -0
  7. package/es/group-component/ColumnsGroup/index.js +1 -0
  8. package/es/group-component/ContextMenu.d.ts +19 -0
  9. package/es/group-component/ContextMenu.js +74 -0
  10. package/es/group-component/InternalTable.d.ts +8 -0
  11. package/es/group-component/InternalTable.js +224 -0
  12. package/es/group-component/TableContainer.d.ts +49 -0
  13. package/es/group-component/TableContainer.js +375 -0
  14. package/es/group-component/TableContainerEdit.d.ts +48 -0
  15. package/es/group-component/TableContainerEdit.js +2068 -0
  16. package/es/group-component/body/EditableCell.d.ts +16 -0
  17. package/es/group-component/body/EditableCell.js +1066 -0
  18. package/es/group-component/body/TableBody.d.ts +14 -0
  19. package/es/group-component/body/TableBody.js +82 -0
  20. package/es/group-component/body/TableBodyCell.d.ts +12 -0
  21. package/es/group-component/body/TableBodyCell.js +587 -0
  22. package/es/group-component/body/TableBodyCellEdit.d.ts +17 -0
  23. package/es/group-component/body/TableBodyCellEdit.js +1398 -0
  24. package/es/group-component/body/TableBodyCellEmpty.d.ts +12 -0
  25. package/es/group-component/body/TableBodyCellEmpty.js +149 -0
  26. package/es/group-component/body/TableBodyRow.d.ts +21 -0
  27. package/es/group-component/body/TableBodyRow.js +199 -0
  28. package/es/group-component/body/TableBodyRowGroupCell.d.ts +12 -0
  29. package/es/group-component/body/TableBodyRowGroupCell.js +567 -0
  30. package/es/group-component/components/ControlCheckbox.d.ts +13 -0
  31. package/es/group-component/components/ControlCheckbox.js +84 -0
  32. package/es/group-component/components/EditForm/EditForm.d.ts +27 -0
  33. package/es/group-component/components/EditForm/EditForm.js +394 -0
  34. package/es/group-component/components/EditForm/index.d.ts +1 -0
  35. package/es/group-component/components/EditForm/index.js +1 -0
  36. package/es/group-component/components/InputControl/InputControl.d.ts +27 -0
  37. package/es/group-component/components/InputControl/InputControl.js +118 -0
  38. package/es/group-component/components/InputControl/index.d.ts +1 -0
  39. package/es/group-component/components/InputControl/index.js +1 -0
  40. package/es/group-component/components/async-select/index.d.ts +11 -0
  41. package/es/group-component/components/async-select/index.js +38 -0
  42. package/es/group-component/components/async-table-select/index.d.ts +11 -0
  43. package/es/group-component/components/async-table-select/index.js +40 -0
  44. package/es/group-component/components/checkbox-control/index.d.ts +13 -0
  45. package/es/group-component/components/checkbox-control/index.js +40 -0
  46. package/es/group-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
  47. package/es/group-component/components/checkbox-filter/CheckboxFilter.js +258 -0
  48. package/es/group-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
  49. package/es/group-component/components/checkbox-filter/FilterSearch.js +36 -0
  50. package/es/group-component/components/command/Command.d.ts +10 -0
  51. package/es/group-component/components/command/Command.js +35 -0
  52. package/es/group-component/components/number/index.d.ts +12 -0
  53. package/es/group-component/components/number/index.js +42 -0
  54. package/es/group-component/components/number-range/index.d.ts +13 -0
  55. package/es/group-component/components/number-range/index.js +79 -0
  56. package/es/group-component/features/operator.d.ts +24 -0
  57. package/es/group-component/features/operator.js +62 -0
  58. package/es/group-component/footer/TableFooter.d.ts +7 -0
  59. package/es/group-component/footer/TableFooter.js +34 -0
  60. package/es/group-component/footer/TableFooterCell.d.ts +7 -0
  61. package/es/group-component/footer/TableFooterCell.js +66 -0
  62. package/es/group-component/footer/TableFooterRow.d.ts +8 -0
  63. package/es/group-component/footer/TableFooterRow.js +30 -0
  64. package/es/group-component/header/TableHead.d.ts +15 -0
  65. package/es/group-component/header/TableHead.js +98 -0
  66. package/es/group-component/header/TableHeadCell.d.ts +15 -0
  67. package/es/group-component/header/TableHeadCell.js +310 -0
  68. package/es/group-component/header/TableHeadCell2.d.ts +17 -0
  69. package/es/group-component/header/TableHeadCell2.js +321 -0
  70. package/es/group-component/header/TableHeadGroupCell.d.ts +17 -0
  71. package/es/group-component/header/TableHeadGroupCell.js +94 -0
  72. package/es/group-component/header/TableHeadRow.d.ts +15 -0
  73. package/es/group-component/header/TableHeadRow.js +52 -0
  74. package/es/group-component/header/renderFilter.d.ts +20 -0
  75. package/es/group-component/header/renderFilter.js +291 -0
  76. package/es/group-component/hook/convert.d.ts +1 -0
  77. package/es/group-component/hook/convert.js +28 -0
  78. package/es/group-component/hook/useColumns.d.ts +28 -0
  79. package/es/group-component/hook/useColumns.js +306 -0
  80. package/es/group-component/hook/useFilterOperator.d.ts +7 -0
  81. package/es/group-component/hook/useFilterOperator.js +33 -0
  82. package/es/group-component/hook/utils.d.ts +220 -0
  83. package/es/group-component/hook/utils.js +2340 -0
  84. package/es/group-component/index.d.ts +2 -0
  85. package/es/group-component/index.js +2 -0
  86. package/es/group-component/style.d.ts +22 -0
  87. package/es/group-component/style.js +48 -0
  88. package/es/group-component/style.scss +1438 -0
  89. package/es/group-component/table/Grid.d.ts +33 -0
  90. package/es/group-component/table/Grid.js +438 -0
  91. package/es/group-component/table/TableWrapper.d.ts +33 -0
  92. package/es/group-component/table/TableWrapper.js +250 -0
  93. package/es/group-component/useContext.d.ts +100 -0
  94. package/es/group-component/useContext.js +21 -0
  95. package/es/table-component/InternalTable.js +6 -1
  96. package/es/table-component/TableContainer.js +4 -2
  97. package/es/table-component/TableContainerEdit.js +2 -2
  98. package/es/table-component/body/TableBodyCell.js +49 -40
  99. package/es/table-component/body/TableBodyCellEdit.js +9 -3
  100. package/es/table-component/body/TableBodyRow.js +4 -1
  101. package/es/table-component/hook/utils.d.ts +1 -0
  102. package/es/table-component/hook/utils.js +15 -7
  103. package/es/table-component/style.js +1 -1
  104. package/es/table-component/table/Grid.js +3 -0
  105. package/es/table-component/useContext.d.ts +5 -0
  106. package/es/table-virtuoso/InternalTable.js +2 -2
  107. package/es/table-virtuoso/body/TableBodyCell.js +2 -7
  108. package/es/table-virtuoso/body/TableBodyCellRowGroup.d.ts +14 -0
  109. package/es/table-virtuoso/body/TableBodyCellRowGroup.js +196 -0
  110. package/es/table-virtuoso/body/TableBodyRow.d.ts +1 -1
  111. package/es/table-virtuoso/body/TableBodyRow.js +43 -1
  112. package/es/table-virtuoso/hook/utils.d.ts +1 -0
  113. package/es/table-virtuoso/hook/utils.js +29 -0
  114. package/es/table-virtuoso/style.js +3 -1
  115. package/es/table-virtuoso/table/Grid.js +2 -2
  116. package/es/table-virtuoso/table/TableWrapper.d.ts +7 -1
  117. package/es/table-virtuoso/table/TableWrapper.js +24 -5
  118. package/es/table-virtuoso/useContext.d.ts +6 -3
  119. package/es/table-virtuoso/useContext.js +18 -0
  120. package/lib/grid-component/TempTable.js +2 -1
  121. package/lib/group-component/ColumnsChoose.d.ts +13 -0
  122. package/lib/group-component/ColumnsChoose.js +221 -0
  123. package/lib/group-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
  124. package/lib/group-component/ColumnsGroup/ColumnsGroup.js +241 -0
  125. package/lib/group-component/ColumnsGroup/index.d.ts +1 -0
  126. package/lib/group-component/ColumnsGroup/index.js +16 -0
  127. package/lib/group-component/ContextMenu.d.ts +19 -0
  128. package/lib/group-component/ContextMenu.js +83 -0
  129. package/lib/group-component/InternalTable.d.ts +8 -0
  130. package/lib/group-component/InternalTable.js +233 -0
  131. package/lib/group-component/TableContainer.d.ts +49 -0
  132. package/lib/group-component/TableContainer.js +382 -0
  133. package/lib/group-component/TableContainerEdit.d.ts +48 -0
  134. package/lib/group-component/TableContainerEdit.js +2075 -0
  135. package/lib/group-component/body/EditableCell.d.ts +16 -0
  136. package/lib/group-component/body/EditableCell.js +1075 -0
  137. package/lib/group-component/body/TableBody.d.ts +14 -0
  138. package/lib/group-component/body/TableBody.js +91 -0
  139. package/lib/group-component/body/TableBodyCell.d.ts +12 -0
  140. package/lib/group-component/body/TableBodyCell.js +595 -0
  141. package/lib/group-component/body/TableBodyCellEdit.d.ts +17 -0
  142. package/lib/group-component/body/TableBodyCellEdit.js +1405 -0
  143. package/lib/group-component/body/TableBodyCellEmpty.d.ts +12 -0
  144. package/lib/group-component/body/TableBodyCellEmpty.js +156 -0
  145. package/lib/group-component/body/TableBodyRow.d.ts +21 -0
  146. package/lib/group-component/body/TableBodyRow.js +206 -0
  147. package/lib/group-component/body/TableBodyRowGroupCell.d.ts +12 -0
  148. package/lib/group-component/body/TableBodyRowGroupCell.js +575 -0
  149. package/lib/group-component/components/ControlCheckbox.d.ts +13 -0
  150. package/lib/group-component/components/ControlCheckbox.js +92 -0
  151. package/lib/group-component/components/EditForm/EditForm.d.ts +27 -0
  152. package/lib/group-component/components/EditForm/EditForm.js +404 -0
  153. package/lib/group-component/components/EditForm/index.d.ts +1 -0
  154. package/lib/group-component/components/EditForm/index.js +16 -0
  155. package/lib/group-component/components/InputControl/InputControl.d.ts +27 -0
  156. package/lib/group-component/components/InputControl/InputControl.js +127 -0
  157. package/lib/group-component/components/InputControl/index.d.ts +1 -0
  158. package/lib/group-component/components/InputControl/index.js +16 -0
  159. package/lib/group-component/components/async-select/index.d.ts +11 -0
  160. package/lib/group-component/components/async-select/index.js +47 -0
  161. package/lib/group-component/components/async-table-select/index.d.ts +11 -0
  162. package/lib/group-component/components/async-table-select/index.js +49 -0
  163. package/lib/group-component/components/checkbox-control/index.d.ts +13 -0
  164. package/lib/group-component/components/checkbox-control/index.js +48 -0
  165. package/lib/group-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
  166. package/lib/group-component/components/checkbox-filter/CheckboxFilter.js +267 -0
  167. package/lib/group-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
  168. package/lib/group-component/components/checkbox-filter/FilterSearch.js +44 -0
  169. package/lib/group-component/components/command/Command.d.ts +10 -0
  170. package/lib/group-component/components/command/Command.js +44 -0
  171. package/lib/group-component/components/number/index.d.ts +12 -0
  172. package/lib/group-component/components/number/index.js +50 -0
  173. package/lib/group-component/components/number-range/index.d.ts +13 -0
  174. package/lib/group-component/components/number-range/index.js +87 -0
  175. package/lib/group-component/features/operator.d.ts +24 -0
  176. package/lib/group-component/features/operator.js +67 -0
  177. package/lib/group-component/footer/TableFooter.d.ts +7 -0
  178. package/lib/group-component/footer/TableFooter.js +44 -0
  179. package/lib/group-component/footer/TableFooterCell.d.ts +7 -0
  180. package/lib/group-component/footer/TableFooterCell.js +75 -0
  181. package/lib/group-component/footer/TableFooterRow.d.ts +8 -0
  182. package/lib/group-component/footer/TableFooterRow.js +37 -0
  183. package/lib/group-component/header/TableHead.d.ts +15 -0
  184. package/lib/group-component/header/TableHead.js +107 -0
  185. package/lib/group-component/header/TableHeadCell.d.ts +15 -0
  186. package/lib/group-component/header/TableHeadCell.js +319 -0
  187. package/lib/group-component/header/TableHeadCell2.d.ts +17 -0
  188. package/lib/group-component/header/TableHeadCell2.js +330 -0
  189. package/lib/group-component/header/TableHeadGroupCell.d.ts +17 -0
  190. package/lib/group-component/header/TableHeadGroupCell.js +103 -0
  191. package/lib/group-component/header/TableHeadRow.d.ts +15 -0
  192. package/lib/group-component/header/TableHeadRow.js +59 -0
  193. package/lib/group-component/header/renderFilter.d.ts +20 -0
  194. package/lib/group-component/header/renderFilter.js +301 -0
  195. package/lib/group-component/hook/convert.d.ts +1 -0
  196. package/lib/group-component/hook/convert.js +34 -0
  197. package/lib/group-component/hook/useColumns.d.ts +28 -0
  198. package/lib/group-component/hook/useColumns.js +318 -0
  199. package/lib/group-component/hook/useFilterOperator.d.ts +7 -0
  200. package/lib/group-component/hook/useFilterOperator.js +40 -0
  201. package/lib/group-component/hook/utils.d.ts +220 -0
  202. package/lib/group-component/hook/utils.js +2468 -0
  203. package/lib/group-component/index.d.ts +2 -0
  204. package/lib/group-component/index.js +9 -0
  205. package/lib/group-component/style.d.ts +22 -0
  206. package/lib/group-component/style.js +55 -0
  207. package/lib/group-component/style.scss +1438 -0
  208. package/lib/group-component/table/Grid.d.ts +33 -0
  209. package/lib/group-component/table/Grid.js +443 -0
  210. package/lib/group-component/table/TableWrapper.d.ts +33 -0
  211. package/lib/group-component/table/TableWrapper.js +259 -0
  212. package/lib/group-component/useContext.d.ts +100 -0
  213. package/lib/group-component/useContext.js +27 -0
  214. package/lib/table-component/InternalTable.js +6 -1
  215. package/lib/table-component/TableContainer.js +4 -2
  216. package/lib/table-component/TableContainerEdit.js +2 -2
  217. package/lib/table-component/body/TableBodyCell.js +49 -40
  218. package/lib/table-component/body/TableBodyCellEdit.js +9 -3
  219. package/lib/table-component/body/TableBodyRow.js +4 -1
  220. package/lib/table-component/hook/utils.d.ts +1 -0
  221. package/lib/table-component/hook/utils.js +16 -7
  222. package/lib/table-component/style.js +1 -1
  223. package/lib/table-component/table/Grid.js +3 -0
  224. package/lib/table-component/useContext.d.ts +5 -0
  225. package/lib/table-virtuoso/InternalTable.js +2 -2
  226. package/lib/table-virtuoso/body/TableBodyCell.js +2 -7
  227. package/lib/table-virtuoso/body/TableBodyCellRowGroup.d.ts +14 -0
  228. package/lib/table-virtuoso/body/TableBodyCellRowGroup.js +203 -0
  229. package/lib/table-virtuoso/body/TableBodyRow.d.ts +1 -1
  230. package/lib/table-virtuoso/body/TableBodyRow.js +43 -1
  231. package/lib/table-virtuoso/hook/utils.d.ts +1 -0
  232. package/lib/table-virtuoso/hook/utils.js +32 -1
  233. package/lib/table-virtuoso/style.js +3 -1
  234. package/lib/table-virtuoso/table/Grid.js +2 -2
  235. package/lib/table-virtuoso/table/TableWrapper.d.ts +7 -1
  236. package/lib/table-virtuoso/table/TableWrapper.js +24 -5
  237. package/lib/table-virtuoso/useContext.d.ts +6 -3
  238. package/lib/table-virtuoso/useContext.js +18 -0
  239. package/package.json +1 -1
@@ -0,0 +1,291 @@
1
+ // import type { IFormat } from "../../tanstack-table/type";
2
+
3
+ // import type { AnyObject } from './type';
4
+
5
+ import React, { Fragment } from "react";
6
+ import moment from "moment/moment";
7
+ import { CustomProvider, DatePicker, DateRangePicker, Empty, Input, Select } from "rc-master-ui";
8
+ import dayjs from "dayjs";
9
+ import { convertDateToDayjs, convertDayjsToDate, convertFormat, getDatepickerFormat, getDateRangeFormat, getTypeFilter, isEmpty } from "../hook/utils";
10
+ import NumberInput from "../components/number";
11
+ import NumberRange from "../components/number-range";
12
+ import CheckboxFilter from "../components/checkbox-filter/CheckboxFilter";
13
+ export const renderFilter = args => {
14
+ const {
15
+ column,
16
+ selectedKeys,
17
+ setSelectedKeys,
18
+ // confirm,
19
+ t,
20
+ locale,
21
+ buddhistLocale,
22
+ dateRangeLocale,
23
+ dataSourceFilter,
24
+ format,
25
+ doFilter
26
+ } = args;
27
+ const {
28
+ format: columnFormat,
29
+ typeFilter,
30
+ type: columnType,
31
+ field,
32
+ source
33
+ } = column?.meta ?? {};
34
+ const cellFormat = columnFormat ? typeof columnFormat === 'function' ? columnFormat({}) : columnFormat : format;
35
+ const type = getTypeFilter(column.meta ?? {});
36
+ const dateFormat = getDatepickerFormat(typeFilter ?? columnType, cellFormat) ?? 'DD/MM/YYYY';
37
+ const dateRangeFormat = convertFormat(getDateRangeFormat(columnType, cellFormat) ?? 'dd/MM/yyyy');
38
+ const find = dataSourceFilter?.find(it => it.key === field);
39
+ const options = find ? find.data : [];
40
+ switch (type) {
41
+ case 'Number':
42
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
43
+ className: 'mb-1'
44
+ }, /*#__PURE__*/React.createElement(NumberInput, {
45
+ t: t,
46
+ value: selectedKeys[0],
47
+ onChange: vals => {
48
+ setSelectedKeys(vals);
49
+ },
50
+ onPressEnter: () => doFilter?.(true)
51
+ }))));
52
+ case 'NumberRange':
53
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(NumberRange, {
54
+ t: t,
55
+ min: selectedKeys[0],
56
+ max: selectedKeys[1],
57
+ onChange: vals => {
58
+ setSelectedKeys(vals);
59
+ },
60
+ onPressEnter: () => doFilter?.(true)
61
+ })));
62
+ case 'Date':
63
+ const dateValue = selectedKeys[0] ? convertDateToDayjs(new Date(selectedKeys[0]), dateFormat) : null;
64
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
65
+ className: 'mb-1'
66
+ }, /*#__PURE__*/React.createElement(DatePicker, {
67
+ format: {
68
+ format: dateFormat,
69
+ type: 'mask'
70
+ },
71
+ locale: buddhistLocale,
72
+ style: {
73
+ width: '100%',
74
+ height: '100%'
75
+ },
76
+ value: dateValue,
77
+ defaultValue: dateValue
78
+ // placeholder={t ? t(column?.placeholder) : column?.placeholder}
79
+ ,
80
+ onChange: (date, dateString) => {
81
+ const newDateValue = dateString ? moment(convertDayjsToDate(dateString, dateFormat)).format() : null;
82
+ setSelectedKeys(newDateValue ? [newDateValue] : []);
83
+ }
84
+ }))));
85
+ case 'DateRange':
86
+ // const dateRangeValue: any = [selectedKeys[0] ? convertDateToDayjs(new Date(selectedKeys[0]), dateRangeFormat) : '', selectedKeys[1] ? convertDateToDayjs(new Date(selectedKeys[1]), dateRangeFormat) : '']
87
+ const dateRangeValue = selectedKeys && selectedKeys.length > 0 ? [selectedKeys[0] ? new Date(selectedKeys[0]) : '', selectedKeys[1] ? new Date(selectedKeys[1]) : ''] : null;
88
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
89
+ className: 'mb-1'
90
+ }, /*#__PURE__*/React.createElement(CustomProvider, {
91
+ locale: dateRangeLocale
92
+ }, /*#__PURE__*/React.createElement(DateRangePicker
93
+ // placeholder={['Ngày bắt đầu', 'Ngày bắt đầu']}
94
+ , {
95
+ style: {
96
+ width: 300
97
+ },
98
+ format: dateRangeFormat,
99
+ value: dateRangeValue,
100
+ onChange: value => {
101
+ const newDateRangeValue = value ? [value[0] ? moment(value[0]).format() : '', value[1] ? moment(value[1]).format() : ''] : [];
102
+ setSelectedKeys(newDateRangeValue);
103
+ },
104
+ menuClassName: "rc-menu-popup"
105
+ })))));
106
+ case 'Week':
107
+ const weekValue = !isEmpty(selectedKeys[0]) ? dayjs(selectedKeys[0], dateFormat) : null;
108
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
109
+ className: 'mb-1'
110
+ }, /*#__PURE__*/React.createElement(DatePicker, {
111
+ format: {
112
+ format: dateFormat,
113
+ type: 'mask'
114
+ },
115
+ picker: 'week',
116
+ locale: buddhistLocale,
117
+ style: {
118
+ width: '100%',
119
+ height: '100%'
120
+ },
121
+ value: weekValue,
122
+ defaultValue: weekValue
123
+ // placeholder={column?.placeholder}
124
+ ,
125
+ onChange: (date, dateString) => {
126
+ const newDateValue = dateString ?? null;
127
+ setSelectedKeys(newDateValue ? [newDateValue] : []);
128
+ }
129
+ }))));
130
+ case 'Month':
131
+ const monthValue = !isEmpty(selectedKeys[0]) ? dayjs(selectedKeys[0], dateFormat) : null;
132
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
133
+ className: 'mb-1'
134
+ }, /*#__PURE__*/React.createElement(DatePicker, {
135
+ format: {
136
+ format: dateFormat,
137
+ type: 'mask'
138
+ },
139
+ picker: 'month',
140
+ locale: buddhistLocale,
141
+ style: {
142
+ width: '100%',
143
+ height: '100%'
144
+ },
145
+ value: monthValue,
146
+ defaultValue: monthValue
147
+ // placeholder={column?.placeholder}
148
+ ,
149
+ onChange: (date, dateString) => {
150
+ const newDateValue = dateString ?? null;
151
+ setSelectedKeys(newDateValue ? [newDateValue] : []);
152
+ }
153
+ })));
154
+
155
+ // // case 'Quarter':
156
+ // //
157
+ // // // const monthValue = selectedKeys[0] ? convertDateToDayjs(new Date(selectedKeys[0]), dateFormat) : null
158
+ // //
159
+ // // const pickerFormat = getDatepickerFormat(getEditType(col) as IEditType, col)
160
+ // // const pickerValue = !isEmpty(selectedKeys[0]) ? dayjs(selectedKeys[0], pickerFormat) : null
161
+ // //
162
+ // // return (
163
+ // // <Fragment>
164
+ // // <div>
165
+ // //
166
+ // //
167
+ // // <div className={'mb-1'}>
168
+ // //
169
+ // // <DatePicker
170
+ // // format={{
171
+ // // format: dateFormat,
172
+ // // type: 'mask'
173
+ // // }}
174
+ // // locale={buddhistLocale}
175
+ // // style={{width: '100%', height: '100%'}}
176
+ // // value={pickerValue}
177
+ // // defaultValue={pickerValue}
178
+ // // placeholder={column.placeholder}
179
+ // // onChange={(date, dateString) => {
180
+ // // const newDateValue = dateString ? moment(convertDayjsToDate(dateString as string, dateFormat)).format() : null
181
+ // // setSelectedKeys(newDateValue ? [newDateValue] : [])
182
+ // //
183
+ // // }}
184
+ // //
185
+ // // />
186
+ // // </div>
187
+ // //
188
+ // //
189
+ // // </div>
190
+ // // </Fragment>
191
+ // // )
192
+ // //
193
+ // // case 'Year':
194
+ // //
195
+ // // // const monthValue = selectedKeys[0] ? convertDateToDayjs(new Date(selectedKeys[0]), dateFormat) : null
196
+ // //
197
+ // // const pickerFormat = getDatepickerFormat(getEditType(col) as IEditType, col)
198
+ // // const pickerValue = !isEmpty(selectedKeys[0]) ? dayjs(selectedKeys[0], pickerFormat) : null
199
+ // //
200
+ // // return (
201
+ // // <Fragment>
202
+ // // <div>
203
+ // //
204
+ // //
205
+ // // <div className={'mb-1'}>
206
+ // //
207
+ // // <DatePicker
208
+ // // format={{
209
+ // // format: dateFormat,
210
+ // // type: 'mask'
211
+ // // }}
212
+ // // locale={buddhistLocale}
213
+ // // style={{width: '100%', height: '100%'}}
214
+ // // value={pickerValue}
215
+ // // defaultValue={pickerValue}
216
+ // // placeholder={column.placeholder}
217
+ // // onChange={(date, dateString) => {
218
+ // // const newDateValue = dateString ? moment(convertDayjsToDate(dateString as string, dateFormat)).format() : null
219
+ // // setSelectedKeys(newDateValue ? [newDateValue] : [])
220
+ // //
221
+ // // }}
222
+ // //
223
+ // // />
224
+ // // </div>
225
+ // //
226
+ // //
227
+ // // </div>
228
+ // // </Fragment>
229
+ // // )
230
+
231
+ case 'Dropdown':
232
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
233
+ className: 'mb-1'
234
+ }, /*#__PURE__*/React.createElement(Select
235
+ // options={translateOption(numberOperator, t)}
236
+ // options={find ? options : column.source ?? []}
237
+ , {
238
+ options: source ? source : options ?? [],
239
+ style: {
240
+ width: '100%',
241
+ marginBottom: 8
242
+ },
243
+ value: selectedKeys[0],
244
+ notFoundContent: /*#__PURE__*/React.createElement(Empty, {
245
+ image: Empty.PRESENTED_IMAGE_SIMPLE,
246
+ description: locale?.emptyText
247
+ }),
248
+ onChange: val => {
249
+ // setOperatorKey(val)
250
+ setSelectedKeys(val ? [val] : []);
251
+ },
252
+ showSearch: true,
253
+ allowClear: true
254
+ }))));
255
+ case 'Checkbox':
256
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
257
+ className: 'mb-1'
258
+ }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(CheckboxFilter, {
259
+ locale: locale,
260
+ selectedKeys: selectedKeys,
261
+ onSelect: val => {
262
+ setSelectedKeys(val);
263
+ }
264
+ // options={options}
265
+ ,
266
+ options: source ? source : options ?? [],
267
+ filterMultiple: true
268
+ // open={visible}
269
+ // searchValue={searchValue}
270
+ // setSearchValue={setSearchValue}
271
+ })))));
272
+ case 'Text':
273
+ default:
274
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
275
+ className: 'mb-1'
276
+ }, /*#__PURE__*/React.createElement(Input, {
277
+ className: "aaaa",
278
+ classNames: {
279
+ input: 'filter-input'
280
+ },
281
+ placeholder: t ? t('Search') : `Search`,
282
+ value: selectedKeys[0],
283
+ onChange: e => setSelectedKeys(e.target.value ? [e.target.value] : [])
284
+ // onPressEnter={() => handleSearch(selectedKeys as string[], confirm)}
285
+ ,
286
+ onPressEnter: () => doFilter?.(true),
287
+ allowClear: true
288
+ // autoFocus={true}
289
+ }))));
290
+ }
291
+ };
@@ -0,0 +1 @@
1
+ export declare function convertColumns(columns: any[]): any[];
@@ -0,0 +1,28 @@
1
+ import { createColumnHelper } from '@tanstack/react-table';
2
+ const columnHelper = createColumnHelper();
3
+ export function convertColumns(columns) {
4
+ return columns.map(col => {
5
+ if (col.columns) {
6
+ // Group column
7
+ return columnHelper.group({
8
+ ...col,
9
+ columns: convertColumns(col.columns) // đệ quy
10
+ });
11
+ } else {
12
+ // Accessor column
13
+ let accessor;
14
+
15
+ // Ưu tiên accessorKey nếu có, nếu không thì dùng hàm row => row[col.id]
16
+ if (col.accessorKey) {
17
+ accessor = col.accessorKey;
18
+ } else if (col.id) {
19
+ accessor = row => row[col.id];
20
+ } else {
21
+ throw new Error('Column không có accessorKey hoặc id');
22
+ }
23
+ return columnHelper.accessor(accessor, {
24
+ ...col
25
+ });
26
+ }
27
+ });
28
+ }
@@ -0,0 +1,28 @@
1
+ import type { Dispatch, SetStateAction } from "react";
2
+ import type { ColumnsTable, ColumnTable, IFormat, SelectionSettings } from '../../grid-component/type';
3
+ import type { Cell, ColumnDef } from '@tanstack/react-table';
4
+ export declare const renderValueCell: <T>(column: ColumnTable<T>, value: any, record: T, rowIndex: number, colIndex: number, format?: IFormat, editAble?: boolean) => any;
5
+ export declare function convertToTanStackColumns<T>({ t, columns, format, editAble }: {
6
+ t?: any;
7
+ columns: ColumnsTable<T>;
8
+ format?: IFormat;
9
+ editAble?: boolean;
10
+ }): ColumnDef<T, any>[];
11
+ export type ToggleRow<T> = {
12
+ e: any;
13
+ cell: Cell<T, unknown>;
14
+ selectionSettings?: SelectionSettings;
15
+ isSelectionChange?: {
16
+ isChange: boolean;
17
+ type: string;
18
+ rowData: T;
19
+ rowsData: T[];
20
+ };
21
+ setIsSelectionChange: Dispatch<SetStateAction<{
22
+ isChange: boolean;
23
+ type: string;
24
+ rowData: T;
25
+ rowsData: T[];
26
+ }>>;
27
+ };
28
+ export declare const toggleRowSelection: <T>(props: ToggleRow<T>) => void;
@@ -0,0 +1,306 @@
1
+ import React, { Fragment } from 'react';
2
+ import ControlCheckbox from "../components/ControlCheckbox";
3
+ import { checkDecimalSeparator, checkThousandSeparator, countUnselectedChildren, excludeItems, getAllChildren, getFormat, isColor, isEmpty, sortByType, toggleRowAndChildren } from "./utils";
4
+ import { numericFormatter } from 'react-numeric-component';
5
+ import dayjs from 'dayjs';
6
+ import moment from 'moment';
7
+ export const renderValueCell = (column, value, record, rowIndex, colIndex, format, editAble) => {
8
+ switch (column?.type) {
9
+ case 'number':
10
+ const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
11
+ const cellFormat = getFormat(colFormat, format);
12
+ const thousandSeparator = cellFormat?.thousandSeparator;
13
+ const decimalSeparator = cellFormat?.decimalSeparator;
14
+ const dec = cellFormat?.decimalScale;
15
+
16
+ // const contentNumber = !isEmpty(value) ? ((dec || dec === 0) ? parseFloat(Number(value).toFixed(dec)).toString() : value.toString()) : '0'
17
+
18
+ const tmpval = typeof value === 'string' ? Number(value) : value;
19
+ const numericFormatProps = {
20
+ thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
21
+ decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
22
+ allowNegative: cellFormat?.allowNegative ?? true,
23
+ prefix: cellFormat?.prefix,
24
+ suffix: cellFormat?.suffix,
25
+ decimalScale: dec,
26
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
27
+ };
28
+
29
+ // if ( typeof value === "string") {
30
+ // const ttt = removeNumericFormat(value, undefined, numericFormatProps )
31
+ //
32
+ // }
33
+
34
+ const contentNumber = !isEmpty(value) ? dec || dec === 0 ? parseFloat(tmpval.toFixed(dec)).toString() : tmpval.toString() : '0';
35
+ // const contentNumber = !isEmpty(value) ? ((dec || dec === 0) ? tmpval.toString() : tmpval.toString()) : '0'
36
+
37
+ return !isEmpty(contentNumber) ? numericFormatter(contentNumber, numericFormatProps) : '';
38
+ case 'date':
39
+ return value ? dayjs(value).format(format?.dateFormat ?? 'DD/MM/YYYY') : '';
40
+ case 'time':
41
+ return value ? value : '';
42
+ case 'year':
43
+ const year = value ? moment(value).format('yyyy') : '';
44
+ return /*#__PURE__*/React.createElement(Fragment, null, year);
45
+ case 'datetime':
46
+ return value ? moment(value).format(format?.datetimeFormat ?? 'DD/MM/YYYY HH:mm') : '';
47
+ case 'boolean':
48
+ return value ? 'true' : 'false';
49
+ case 'color':
50
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
51
+ className: 'w-100 h-100',
52
+ style: {
53
+ backgroundColor: isColor(value) ? value : '#fff',
54
+ border: '1px solid #f0f0f0',
55
+ height: '100%',
56
+ minHeight: 20
57
+ }
58
+ }));
59
+ case 'checkbox':
60
+ return /*#__PURE__*/React.createElement(ControlCheckbox, {
61
+ column: column,
62
+ record: record,
63
+ rowIndex: rowIndex,
64
+ colIndex: colIndex,
65
+ checked: !!value,
66
+ checkValue: value,
67
+ editAble: editAble
68
+ });
69
+ case 'file':
70
+ 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(", ") : '';
71
+ return value ? nameFile : '';
72
+ default:
73
+ if (Array.isArray(value)) {
74
+ return value.join(', ');
75
+ }
76
+ return value;
77
+ }
78
+ };
79
+ export function convertToTanStackColumns({
80
+ t,
81
+ columns,
82
+ // expanded,
83
+ // setExpanded,
84
+ // expandable,
85
+ format,
86
+ editAble
87
+ }) {
88
+ // const expandIconColumnIndex = expandable?.expandIconColumnIndex ?? 0
89
+
90
+ return sortByType(columns).map(col => {
91
+ const {
92
+ headerText,
93
+ headerTemplate,
94
+ field,
95
+ width,
96
+ allowResizing,
97
+ minWidth,
98
+ template,
99
+ allowSortering,
100
+ allowFiltering
101
+ } = col;
102
+ const {
103
+ children,
104
+ ...restProps
105
+ } = col;
106
+ const newCol = {
107
+ header: () => {
108
+ if (headerTemplate) {
109
+ if (typeof headerTemplate === 'function') {
110
+ return headerTemplate(col);
111
+ } else {
112
+ return headerTemplate;
113
+ }
114
+ } else {
115
+ return t ? t(headerText) : headerText;
116
+ // return field
117
+ }
118
+ },
119
+ cell: props => {
120
+ const {
121
+ getValue,
122
+ cell
123
+ } = props;
124
+ const cellValue = props.renderValue() ?? null;
125
+ const record = cell.row.original;
126
+ const colIndex = cell.column.getIndex();
127
+ const rowIndex = cell.row.index;
128
+ if (template) {
129
+ if (typeof template === 'function') {
130
+ return template({
131
+ field: field ?? '',
132
+ index: cell.row.index,
133
+ rowData: cell.row.original,
134
+ value: getValue()
135
+ });
136
+ } else {
137
+ return template;
138
+ }
139
+ } else {
140
+ return /*#__PURE__*/React.createElement(Fragment, null, renderValueCell(col, cellValue, record, rowIndex, colIndex, format, editAble));
141
+ }
142
+ },
143
+ enableResizing: allowResizing !== false,
144
+ // enableHiding: false,
145
+ // enableResizing: true,
146
+ id: field,
147
+ size: width,
148
+ accessorKey: field,
149
+ sortDescFirst: false,
150
+ minSize: minWidth,
151
+ // maxSize: maxWidth,
152
+ enableSorting: allowSortering !== false,
153
+ // enableSorting: false,
154
+ // enableColumnFilter: allowFiltering !== false && !nonActionColumn.includes(field)
155
+ enableColumnFilter: allowFiltering !== false
156
+ };
157
+ if (children) {
158
+ newCol.size = undefined;
159
+ // @ts-ignore
160
+ newCol.columns = convertToTanStackColumns({
161
+ columns: children,
162
+ editAble,
163
+ format,
164
+ t
165
+ });
166
+ }
167
+ const meta = {
168
+ ...restProps
169
+ };
170
+ if (Object.keys(meta).length > 0) {
171
+ newCol.meta = meta;
172
+ }
173
+ return newCol;
174
+ });
175
+ }
176
+ export const toggleRowSelection = props => {
177
+ const {
178
+ selectionSettings,
179
+ cell,
180
+ isSelectionChange,
181
+ e,
182
+ setIsSelectionChange
183
+ } = props;
184
+ const {
185
+ row
186
+ } = cell;
187
+ const {
188
+ rowsData
189
+ } = isSelectionChange ?? {};
190
+ const prevSelected = rowsData && rowsData.length > 0 ? [...rowsData] : [];
191
+ if (selectionSettings?.checkStrictly || selectionSettings?.type === 'single') {
192
+ row.getToggleSelectedHandler()(e);
193
+ if (row.getIsSelected()) {
194
+ // đã chọn
195
+
196
+ // xóa row ra list selected
197
+ const newRowsSelected = prevSelected.filter(it => it.id !== row.id);
198
+ setIsSelectionChange({
199
+ isChange: true,
200
+ type: 'rowSelected',
201
+ rowData: row.original,
202
+ rowsData: newRowsSelected ?? []
203
+ });
204
+ } else {
205
+ // chưa selected
206
+
207
+ const checkedRows = [...prevSelected, row];
208
+ setIsSelectionChange({
209
+ isChange: true,
210
+ type: 'rowSelected',
211
+ rowData: row.original,
212
+ rowsData: selectionSettings?.type === 'single' ? [row] : checkedRows
213
+ });
214
+ }
215
+ return;
216
+ }
217
+ if (row.subRows && row.subRows.length > 0) {
218
+ // click vào row cha
219
+
220
+ const allChild = getAllChildren(row);
221
+ toggleRowAndChildren(row, !row.getIsSelected());
222
+ if (row.getIsSelected()) {
223
+ // đã chọn
224
+
225
+ // const aaa = isSelectionChange?.rowsData.filter((it) => it.id !== row.id)
226
+
227
+ const newRowsSelected = excludeItems(prevSelected, [...allChild, row]);
228
+ setIsSelectionChange({
229
+ isChange: true,
230
+ type: 'rowSelected',
231
+ rowData: row.original,
232
+ rowsData: newRowsSelected ?? []
233
+ });
234
+ } else {
235
+ // chưa selected
236
+
237
+ let checkedRows = [];
238
+ if (row.subRows && row.subRows.length > 0) {
239
+ checkedRows = [...prevSelected, row, ...allChild];
240
+ } else {
241
+ checkedRows = [...prevSelected, row];
242
+ }
243
+ setIsSelectionChange({
244
+ isChange: true,
245
+ type: 'rowSelected',
246
+ rowData: row.original,
247
+ rowsData: checkedRows
248
+ });
249
+ }
250
+ } else {
251
+ // click vào row không có cha
252
+
253
+ row.getToggleSelectedHandler()(e);
254
+ if (row.getIsSelected()) {
255
+ // đã chọn
256
+
257
+ const rowParent = row.getParentRow();
258
+ // const rowParent1 = row.getParentRows()
259
+
260
+ let newCheckedRows = [];
261
+ if (rowParent) {}
262
+ if (rowParent && countUnselectedChildren(row) === 1) {
263
+ newCheckedRows = prevSelected.filter(it => it.id !== row.id && it.id !== rowParent.id);
264
+ } else {
265
+ // xóa row ra list selected
266
+ // const newRowsSelected = prevSelected.filter((it) => it.id !== row.id)
267
+ newCheckedRows = prevSelected.filter(it => it.id !== row.id);
268
+ }
269
+ setIsSelectionChange({
270
+ isChange: true,
271
+ type: 'rowSelected',
272
+ rowData: row.original,
273
+ rowsData: newCheckedRows ?? []
274
+ });
275
+ } else {
276
+ // chưa selected
277
+
278
+ let checkedRows = [];
279
+ const rowParent = row.getParentRow();
280
+
281
+ // nếu có cha và cha chưa được chọn và tất cả con đã chọn => thêm row cha vào
282
+ if (rowParent && !rowParent.getIsSelected() && countUnselectedChildren(row) === 1) {
283
+ rowParent.toggleSelected(!rowParent.getIsSelected());
284
+ checkedRows = [...prevSelected, row, rowParent];
285
+ } else {
286
+ // chỉ thêm vào row hiện tại
287
+
288
+ const isInclude = prevSelected.findIndex(it => it.id === cell.row.id);
289
+ if (isInclude > -1) {
290
+ // cập nhật data row hiện tại
291
+
292
+ prevSelected[isInclude] = row;
293
+ checkedRows = [...prevSelected];
294
+ } else {
295
+ checkedRows = [...prevSelected, row];
296
+ }
297
+ }
298
+ setIsSelectionChange({
299
+ isChange: true,
300
+ type: 'rowSelected',
301
+ rowData: row.original,
302
+ rowsData: checkedRows
303
+ });
304
+ }
305
+ }
306
+ };
@@ -0,0 +1,7 @@
1
+ import type { Table } from '@tanstack/react-table';
2
+ import type { FilterOperator } from '../../grid-component/type';
3
+ export declare function useFilterOperator(table: Table<any>): {
4
+ setFilterOperator: (columnId: string, operator: FilterOperator) => void;
5
+ getFilterOperator: (columnId: string) => FilterOperator;
6
+ };
7
+ export declare function customStringFilterFn(row: any, columnId: any, filterValue: any): boolean;