react-table-edit 0.4.0 → 0.4.1

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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import { ReactNode } from 'react';
2
+ import { ReactNode, Dispatch, SetStateAction } from 'react';
3
3
  import { TFunction } from 'react-i18next';
4
4
 
5
5
  type ITextAlign = 'center' | 'left' | 'right';
@@ -93,16 +93,18 @@ type IFTableEditToolbar = {
93
93
  toolbarBottomOptions?: IFToolbarOptions[];
94
94
  showBottomToolbar?: boolean;
95
95
  };
96
+ type IFTableEditSearchSetting = {
97
+ searchEnable?: boolean;
98
+ searchTerm?: string;
99
+ setSearchTerm?: Dispatch<SetStateAction<string>>;
100
+ keyField?: string[];
101
+ };
96
102
  type IFTableEditProps = {
97
103
  idTable?: string;
98
104
  dataSource: any[];
99
- haveSum?: boolean;
100
105
  selectEnable?: boolean;
101
106
  defaultValue?: any;
102
107
  columns: IColumnTable[];
103
- pagingSetting?: IFTableEditPaging;
104
- buttonSetting?: IFTableEditButton;
105
- toolbarSetting?: IFTableEditToolbar;
106
108
  setDataSource?: any;
107
109
  commandClick?: any;
108
110
  rowChange?: any;
@@ -111,16 +113,18 @@ type IFTableEditProps = {
111
113
  height?: number;
112
114
  maxHeight?: number;
113
115
  minHeight?: number;
114
- searchTerm?: string;
115
- setSearchTerm?: any;
116
116
  selectedItem?: any;
117
- setSelectedItem?: any;
118
- searchEnable?: boolean;
117
+ setSelectedItem?: Dispatch<SetStateAction<any>>;
119
118
  isMulti?: boolean;
120
- decimalSeparator?: string;
121
- thousandSeparator?: string;
119
+ haveSum?: boolean;
122
120
  editDisable?: boolean;
123
121
  addDisable?: boolean;
122
+ decimalSeparator?: string;
123
+ thousandSeparator?: string;
124
+ pagingSetting?: IFTableEditPaging;
125
+ buttonSetting?: IFTableEditButton;
126
+ toolbarSetting?: IFTableEditToolbar;
127
+ searchSetting?: IFTableEditSearchSetting;
124
128
  };
125
129
  type IFPageSize = {
126
130
  pageSize: number;
@@ -178,4 +182,4 @@ declare const objSymbolThousand: any;
178
182
  declare const formartNumberic: (str: string | number, decimalSeparator: string, thousandSeparator: string, fraction?: number, isDone?: boolean) => string;
179
183
  declare const roundNumber: (num: number, fraction: number) => number;
180
184
 
181
- export { type FromItemsField, type IColumnTable, type ICommandItem, type IFCurrentPage, type IFCurrentPageConfig, type IFPageSize, type IFTableEditButton, type IFTableEditPaging, type IFTableEditProps, type IFTableEditToolbar, type IFToolbarOptions, type ISettingFormElement, type ISettingNumericElement, type ISettingSelectElement, TableEdit as default, formartNumberic, generateUUID, isNullOrUndefined, messageBoxConfirm, messageBoxConfirm2, messageBoxConfirmDelete, messageBoxError, messageHtmlBoxConfirm, messageHtmlBoxError, notificationError, notificationSuccess, objSymbolDecimal, objSymbolThousand, roundNumber, useOnClickOutside };
185
+ export { type FromItemsField, type IColumnTable, type ICommandItem, type IFCurrentPage, type IFCurrentPageConfig, type IFPageSize, type IFTableEditButton, type IFTableEditPaging, type IFTableEditProps, type IFTableEditSearchSetting, type IFTableEditToolbar, type IFToolbarOptions, type ISettingFormElement, type ISettingNumericElement, type ISettingSelectElement, TableEdit as default, formartNumberic, generateUUID, isNullOrUndefined, messageBoxConfirm, messageBoxConfirm2, messageBoxConfirmDelete, messageBoxError, messageHtmlBoxConfirm, messageHtmlBoxError, notificationError, notificationSuccess, objSymbolDecimal, objSymbolThousand, roundNumber, useOnClickOutside };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import { ReactNode } from 'react';
2
+ import { ReactNode, Dispatch, SetStateAction } from 'react';
3
3
  import { TFunction } from 'react-i18next';
4
4
 
5
5
  type ITextAlign = 'center' | 'left' | 'right';
@@ -93,16 +93,18 @@ type IFTableEditToolbar = {
93
93
  toolbarBottomOptions?: IFToolbarOptions[];
94
94
  showBottomToolbar?: boolean;
95
95
  };
96
+ type IFTableEditSearchSetting = {
97
+ searchEnable?: boolean;
98
+ searchTerm?: string;
99
+ setSearchTerm?: Dispatch<SetStateAction<string>>;
100
+ keyField?: string[];
101
+ };
96
102
  type IFTableEditProps = {
97
103
  idTable?: string;
98
104
  dataSource: any[];
99
- haveSum?: boolean;
100
105
  selectEnable?: boolean;
101
106
  defaultValue?: any;
102
107
  columns: IColumnTable[];
103
- pagingSetting?: IFTableEditPaging;
104
- buttonSetting?: IFTableEditButton;
105
- toolbarSetting?: IFTableEditToolbar;
106
108
  setDataSource?: any;
107
109
  commandClick?: any;
108
110
  rowChange?: any;
@@ -111,16 +113,18 @@ type IFTableEditProps = {
111
113
  height?: number;
112
114
  maxHeight?: number;
113
115
  minHeight?: number;
114
- searchTerm?: string;
115
- setSearchTerm?: any;
116
116
  selectedItem?: any;
117
- setSelectedItem?: any;
118
- searchEnable?: boolean;
117
+ setSelectedItem?: Dispatch<SetStateAction<any>>;
119
118
  isMulti?: boolean;
120
- decimalSeparator?: string;
121
- thousandSeparator?: string;
119
+ haveSum?: boolean;
122
120
  editDisable?: boolean;
123
121
  addDisable?: boolean;
122
+ decimalSeparator?: string;
123
+ thousandSeparator?: string;
124
+ pagingSetting?: IFTableEditPaging;
125
+ buttonSetting?: IFTableEditButton;
126
+ toolbarSetting?: IFTableEditToolbar;
127
+ searchSetting?: IFTableEditSearchSetting;
124
128
  };
125
129
  type IFPageSize = {
126
130
  pageSize: number;
@@ -178,4 +182,4 @@ declare const objSymbolThousand: any;
178
182
  declare const formartNumberic: (str: string | number, decimalSeparator: string, thousandSeparator: string, fraction?: number, isDone?: boolean) => string;
179
183
  declare const roundNumber: (num: number, fraction: number) => number;
180
184
 
181
- export { type FromItemsField, type IColumnTable, type ICommandItem, type IFCurrentPage, type IFCurrentPageConfig, type IFPageSize, type IFTableEditButton, type IFTableEditPaging, type IFTableEditProps, type IFTableEditToolbar, type IFToolbarOptions, type ISettingFormElement, type ISettingNumericElement, type ISettingSelectElement, TableEdit as default, formartNumberic, generateUUID, isNullOrUndefined, messageBoxConfirm, messageBoxConfirm2, messageBoxConfirmDelete, messageBoxError, messageHtmlBoxConfirm, messageHtmlBoxError, notificationError, notificationSuccess, objSymbolDecimal, objSymbolThousand, roundNumber, useOnClickOutside };
185
+ export { type FromItemsField, type IColumnTable, type ICommandItem, type IFCurrentPage, type IFCurrentPageConfig, type IFPageSize, type IFTableEditButton, type IFTableEditPaging, type IFTableEditProps, type IFTableEditSearchSetting, type IFTableEditToolbar, type IFToolbarOptions, type ISettingFormElement, type ISettingNumericElement, type ISettingSelectElement, TableEdit as default, formartNumberic, generateUUID, isNullOrUndefined, messageBoxConfirm, messageBoxConfirm2, messageBoxConfirmDelete, messageBoxError, messageHtmlBoxConfirm, messageHtmlBoxError, notificationError, notificationSuccess, objSymbolDecimal, objSymbolThousand, roundNumber, useOnClickOutside };
package/dist/index.js CHANGED
@@ -1496,9 +1496,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
1496
1496
  defaultValue,
1497
1497
  haveSum,
1498
1498
  toolbarSetting,
1499
- searchTerm,
1500
- setSearchTerm,
1501
- searchEnable,
1499
+ searchSetting,
1502
1500
  setSelectedItem,
1503
1501
  selectedItem,
1504
1502
  selectEnable,
@@ -1526,12 +1524,14 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
1526
1524
  const [objWidthFix, setObjWidthFix] = (0, import_react12.useState)({});
1527
1525
  const [openPopupTree, setOpenPopupTree] = (0, import_react12.useState)(false);
1528
1526
  const [openPopupSetupColumn, setOpenPopupSetupColumn] = (0, import_react12.useState)(false);
1527
+ const [searchTerm, setSearchTerm] = (0, import_react12.useState)("");
1529
1528
  const tableElement = (0, import_react12.useRef)(null);
1530
1529
  const gridRef = (0, import_react12.useRef)();
1531
1530
  const lag = window.localStorage.getItem("i18nextLng");
1532
1531
  const lang = lag ? lag : "vi";
1533
1532
  const pagingClient = pagingSetting?.allowPaging && !(editDisable || addDisable);
1534
- const totalCount = dataSource.length;
1533
+ const searchClient = searchSetting?.searchEnable && !(editDisable || addDisable);
1534
+ let totalCount = dataSource.length;
1535
1535
  const fieldKey = columns.find((item) => item.isPrimarykey === true)?.field ?? "id";
1536
1536
  const fieldUniKey = columns.filter((item) => item.isUnikey === true)?.map((item) => item.field);
1537
1537
  (0, import_react12.useEffect)(() => {
@@ -1668,8 +1668,13 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
1668
1668
  };
1669
1669
  const handleKeyPress = (e) => {
1670
1670
  if (e.code === "Enter" || e.code === "NumpadEnter") {
1671
- setSearchTerm(e.target.value);
1671
+ if (searchSetting?.setSearchTerm) {
1672
+ searchSetting?.setSearchTerm(e.target.value);
1673
+ } else {
1674
+ setSearchTerm(e.target.value);
1675
+ }
1672
1676
  e.stopPropagation();
1677
+ e.preventDefault();
1673
1678
  }
1674
1679
  };
1675
1680
  const searchTemplate = () => {
@@ -1677,14 +1682,14 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
1677
1682
  react_input_default,
1678
1683
  {
1679
1684
  style: { width: "230px" },
1680
- value: searchTerm,
1681
- setSearchTerm,
1685
+ value: searchSetting?.searchTerm !== void 0 ? searchSetting?.searchTerm : searchTerm,
1686
+ setSearchTerm: searchSetting?.setSearchTerm ? searchSetting?.setSearchTerm : setSearchTerm,
1682
1687
  placeholder: t("Search"),
1683
1688
  onKeyPress: handleKeyPress
1684
1689
  }
1685
1690
  ) }) });
1686
1691
  };
1687
- const defaultToolbarOption = searchEnable === true ? [{ template: searchTemplate, align: "left" }] : [];
1692
+ const defaultToolbarOption = searchSetting?.searchEnable ? [{ template: searchTemplate, align: "left" }] : [];
1688
1693
  let toolbarTopOption = [];
1689
1694
  if (toolbarSetting?.toolbarOptions) {
1690
1695
  toolbarTopOption = [...defaultToolbarOption, ...toolbarSetting?.toolbarOptions];
@@ -2870,6 +2875,39 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2870
2875
  ] })
2871
2876
  ] }) });
2872
2877
  };
2878
+ const checkSearch = (keyword, data, fieldKey2) => {
2879
+ if (!keyword || fieldKey2.length === 0) {
2880
+ return true;
2881
+ }
2882
+ for (let index = 0; index < fieldKey2.length; index++) {
2883
+ const key = fieldKey2[index].trim();
2884
+ if (data[key] && data[key].toString().trim().toLowerCase().includes(keyword.trim().toLowerCase())) {
2885
+ return true;
2886
+ }
2887
+ }
2888
+ return false;
2889
+ };
2890
+ const renderData = () => {
2891
+ totalCount = 0;
2892
+ return dataSource.map((row, indexRow) => {
2893
+ const isSelected = selectedRows?.some((x) => x[fieldKey] === row[fieldKey]);
2894
+ const flagSearch = !searchClient || checkSearch(searchSetting?.searchTerm !== void 0 ? searchSetting?.searchTerm : searchTerm, row, searchSetting?.keyField ?? []);
2895
+ if (flagSearch) {
2896
+ totalCount += 1;
2897
+ const flagDisplay = !pagingClient || totalCount > (pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0) - 1) && totalCount <= (pagingSetting.pageSize ?? 0) * (pagingSetting.currentPage ?? 0);
2898
+ return flagDisplay && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2899
+ "tr",
2900
+ {
2901
+ className: (0, import_classnames10.default)("r-row", { "last-row": indexRow === (pagingClient ? totalCount % (pagingSetting?.pageSize ?? 0) : totalCount - 1) }, { "fisrt-row": indexRow === 0 }),
2902
+ children: contentColumns.map((col, indexCol) => {
2903
+ return renderContentCol(col, row, indexRow, indexCol, isSelected);
2904
+ })
2905
+ },
2906
+ `row-${indexRow}`
2907
+ );
2908
+ }
2909
+ });
2910
+ };
2873
2911
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_react12.Fragment, { children: [
2874
2912
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "react-table-edit", children: [
2875
2913
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "r-grid", ref: gridRef, children: [
@@ -2880,20 +2918,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2880
2918
  return renderHeaderCol(col, index, indexParent);
2881
2919
  }) }, indexParent);
2882
2920
  }) }),
2883
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("tbody", { className: "r-gridcontent", children: dataSource.map((row, indexRow) => {
2884
- const isSelected = selectedRows?.some((x) => x[fieldKey] === row[fieldKey]);
2885
- const flagDisplay = !pagingClient || indexRow + 1 > (pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0) - 1) && indexRow < (pagingSetting.pageSize ?? 0) * (pagingSetting.currentPage ?? 0);
2886
- return flagDisplay && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2887
- "tr",
2888
- {
2889
- className: (0, import_classnames10.default)("r-row", { "last-row": indexRow === (pagingClient ? totalCount % (pagingSetting?.pageSize ?? 0) : totalCount - 1) }, { "fisrt-row": indexRow === 0 }),
2890
- children: contentColumns.map((col, indexCol) => {
2891
- return renderContentCol(col, row, indexRow, indexCol, isSelected);
2892
- })
2893
- },
2894
- `row-${indexRow}`
2895
- );
2896
- }) }),
2921
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("tbody", { className: "r-gridcontent", children: renderData() }),
2897
2922
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("tfoot", { className: "r-gridfoot", children: haveSum == true ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("tr", { className: "r-row", children: contentColumns.map((col, index) => {
2898
2923
  return renderFooterCol(col, index);
2899
2924
  }) }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, {}) })
package/dist/index.mjs CHANGED
@@ -1455,9 +1455,7 @@ var TableEdit = forwardRef2((props, ref) => {
1455
1455
  defaultValue,
1456
1456
  haveSum,
1457
1457
  toolbarSetting,
1458
- searchTerm,
1459
- setSearchTerm,
1460
- searchEnable,
1458
+ searchSetting,
1461
1459
  setSelectedItem,
1462
1460
  selectedItem,
1463
1461
  selectEnable,
@@ -1485,12 +1483,14 @@ var TableEdit = forwardRef2((props, ref) => {
1485
1483
  const [objWidthFix, setObjWidthFix] = useState5({});
1486
1484
  const [openPopupTree, setOpenPopupTree] = useState5(false);
1487
1485
  const [openPopupSetupColumn, setOpenPopupSetupColumn] = useState5(false);
1486
+ const [searchTerm, setSearchTerm] = useState5("");
1488
1487
  const tableElement = useRef2(null);
1489
1488
  const gridRef = useRef2();
1490
1489
  const lag = window.localStorage.getItem("i18nextLng");
1491
1490
  const lang = lag ? lag : "vi";
1492
1491
  const pagingClient = pagingSetting?.allowPaging && !(editDisable || addDisable);
1493
- const totalCount = dataSource.length;
1492
+ const searchClient = searchSetting?.searchEnable && !(editDisable || addDisable);
1493
+ let totalCount = dataSource.length;
1494
1494
  const fieldKey = columns.find((item) => item.isPrimarykey === true)?.field ?? "id";
1495
1495
  const fieldUniKey = columns.filter((item) => item.isUnikey === true)?.map((item) => item.field);
1496
1496
  useEffect5(() => {
@@ -1627,8 +1627,13 @@ var TableEdit = forwardRef2((props, ref) => {
1627
1627
  };
1628
1628
  const handleKeyPress = (e) => {
1629
1629
  if (e.code === "Enter" || e.code === "NumpadEnter") {
1630
- setSearchTerm(e.target.value);
1630
+ if (searchSetting?.setSearchTerm) {
1631
+ searchSetting?.setSearchTerm(e.target.value);
1632
+ } else {
1633
+ setSearchTerm(e.target.value);
1634
+ }
1631
1635
  e.stopPropagation();
1636
+ e.preventDefault();
1632
1637
  }
1633
1638
  };
1634
1639
  const searchTemplate = () => {
@@ -1636,14 +1641,14 @@ var TableEdit = forwardRef2((props, ref) => {
1636
1641
  react_input_default,
1637
1642
  {
1638
1643
  style: { width: "230px" },
1639
- value: searchTerm,
1640
- setSearchTerm,
1644
+ value: searchSetting?.searchTerm !== void 0 ? searchSetting?.searchTerm : searchTerm,
1645
+ setSearchTerm: searchSetting?.setSearchTerm ? searchSetting?.setSearchTerm : setSearchTerm,
1641
1646
  placeholder: t("Search"),
1642
1647
  onKeyPress: handleKeyPress
1643
1648
  }
1644
1649
  ) }) });
1645
1650
  };
1646
- const defaultToolbarOption = searchEnable === true ? [{ template: searchTemplate, align: "left" }] : [];
1651
+ const defaultToolbarOption = searchSetting?.searchEnable ? [{ template: searchTemplate, align: "left" }] : [];
1647
1652
  let toolbarTopOption = [];
1648
1653
  if (toolbarSetting?.toolbarOptions) {
1649
1654
  toolbarTopOption = [...defaultToolbarOption, ...toolbarSetting?.toolbarOptions];
@@ -2829,6 +2834,39 @@ var TableEdit = forwardRef2((props, ref) => {
2829
2834
  ] })
2830
2835
  ] }) });
2831
2836
  };
2837
+ const checkSearch = (keyword, data, fieldKey2) => {
2838
+ if (!keyword || fieldKey2.length === 0) {
2839
+ return true;
2840
+ }
2841
+ for (let index = 0; index < fieldKey2.length; index++) {
2842
+ const key = fieldKey2[index].trim();
2843
+ if (data[key] && data[key].toString().trim().toLowerCase().includes(keyword.trim().toLowerCase())) {
2844
+ return true;
2845
+ }
2846
+ }
2847
+ return false;
2848
+ };
2849
+ const renderData = () => {
2850
+ totalCount = 0;
2851
+ return dataSource.map((row, indexRow) => {
2852
+ const isSelected = selectedRows?.some((x) => x[fieldKey] === row[fieldKey]);
2853
+ const flagSearch = !searchClient || checkSearch(searchSetting?.searchTerm !== void 0 ? searchSetting?.searchTerm : searchTerm, row, searchSetting?.keyField ?? []);
2854
+ if (flagSearch) {
2855
+ totalCount += 1;
2856
+ const flagDisplay = !pagingClient || totalCount > (pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0) - 1) && totalCount <= (pagingSetting.pageSize ?? 0) * (pagingSetting.currentPage ?? 0);
2857
+ return flagDisplay && /* @__PURE__ */ jsx12(
2858
+ "tr",
2859
+ {
2860
+ className: classnames6("r-row", { "last-row": indexRow === (pagingClient ? totalCount % (pagingSetting?.pageSize ?? 0) : totalCount - 1) }, { "fisrt-row": indexRow === 0 }),
2861
+ children: contentColumns.map((col, indexCol) => {
2862
+ return renderContentCol(col, row, indexRow, indexCol, isSelected);
2863
+ })
2864
+ },
2865
+ `row-${indexRow}`
2866
+ );
2867
+ }
2868
+ });
2869
+ };
2832
2870
  return /* @__PURE__ */ jsxs11(Fragment12, { children: [
2833
2871
  /* @__PURE__ */ jsxs11("div", { className: "react-table-edit", children: [
2834
2872
  /* @__PURE__ */ jsxs11("div", { className: "r-grid", ref: gridRef, children: [
@@ -2839,20 +2877,7 @@ var TableEdit = forwardRef2((props, ref) => {
2839
2877
  return renderHeaderCol(col, index, indexParent);
2840
2878
  }) }, indexParent);
2841
2879
  }) }),
2842
- /* @__PURE__ */ jsx12("tbody", { className: "r-gridcontent", children: dataSource.map((row, indexRow) => {
2843
- const isSelected = selectedRows?.some((x) => x[fieldKey] === row[fieldKey]);
2844
- const flagDisplay = !pagingClient || indexRow + 1 > (pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0) - 1) && indexRow < (pagingSetting.pageSize ?? 0) * (pagingSetting.currentPage ?? 0);
2845
- return flagDisplay && /* @__PURE__ */ jsx12(
2846
- "tr",
2847
- {
2848
- className: classnames6("r-row", { "last-row": indexRow === (pagingClient ? totalCount % (pagingSetting?.pageSize ?? 0) : totalCount - 1) }, { "fisrt-row": indexRow === 0 }),
2849
- children: contentColumns.map((col, indexCol) => {
2850
- return renderContentCol(col, row, indexRow, indexCol, isSelected);
2851
- })
2852
- },
2853
- `row-${indexRow}`
2854
- );
2855
- }) }),
2880
+ /* @__PURE__ */ jsx12("tbody", { className: "r-gridcontent", children: renderData() }),
2856
2881
  /* @__PURE__ */ jsx12("tfoot", { className: "r-gridfoot", children: haveSum == true ? /* @__PURE__ */ jsx12("tr", { className: "r-row", children: contentColumns.map((col, index) => {
2857
2882
  return renderFooterCol(col, index);
2858
2883
  }) }) : /* @__PURE__ */ jsx12(Fragment13, {}) })
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-table-edit",
3
3
  "license": "MIT",
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",