react-table-edit 1.4.38 → 1.4.40

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.mjs CHANGED
@@ -17696,8 +17696,15 @@ const calculateTableStructure = (columns, settingColumns) => {
17696
17696
  const column = settingColumns.find((y) => y.field === cell.field);
17697
17697
  if (column) {
17698
17698
  cell.visible = column.visible;
17699
- cell.fixedType = column.fixedType;
17700
- cell.width = column.width;
17699
+ if (column.fixedType !== undefined && column.fixedType !== null) {
17700
+ cell.fixedType = column.fixedType;
17701
+ }
17702
+ if (column.width !== undefined && column.width !== null) {
17703
+ cell.width = column.width;
17704
+ }
17705
+ if (column.headerText !== undefined && column.headerText !== null) {
17706
+ cell.headerText = column.headerText;
17707
+ }
17701
17708
  }
17702
17709
  else {
17703
17710
  cell.visible = false;
@@ -17705,24 +17712,24 @@ const calculateTableStructure = (columns, settingColumns) => {
17705
17712
  }
17706
17713
  levels[level].push(cell);
17707
17714
  const headerKey = `${level}-${indexCol}`;
17708
- if (col.fixedType === "left" && col.visible !== false) {
17715
+ if (cell.fixedType === "left" && cell.visible !== false) {
17709
17716
  objHeaderWidthFixLeft[headerKey] = leftTotal;
17710
17717
  }
17711
17718
  if (!hasChildren) {
17712
17719
  const index = flat.length;
17713
- const width = col.width ?? 40;
17720
+ const width = cell.width ?? 40;
17714
17721
  cell.index = index;
17715
17722
  flat.push(cell);
17716
- if (col.fixedType === "left" && col.visible !== false) {
17723
+ if (cell.fixedType === "left" && cell.visible !== false) {
17717
17724
  objWidthFixLeft[index] = leftTotal;
17718
17725
  leftTotal += width;
17719
17726
  }
17720
- if (col.fixedType === "right" && col.in !== false) {
17727
+ if (cell.fixedType === "right" && cell.visible !== false) {
17721
17728
  rightTotal -= width;
17722
17729
  objWidthFixRight[index] = rightTotal;
17723
17730
  }
17724
17731
  }
17725
- if (col.fixedType === "right" && col.visible !== false) {
17732
+ if (cell.fixedType === "right" && cell.visible !== false) {
17726
17733
  objHeaderWidthFixRight[headerKey] = rightTotal;
17727
17734
  }
17728
17735
  return colspanSum + colspan;
@@ -40337,7 +40344,7 @@ const Sidebar = (props) => {
40337
40344
  };
40338
40345
 
40339
40346
  const SidebarSetColumn = (props) => {
40340
- const { column, setColumn, openSidebar, handleSidebar } = props;
40347
+ const { column, setColumn, openSidebar, handleSidebar, resetDefaultColumns, formatSetting } = props;
40341
40348
  const { t } = useTranslation();
40342
40349
  const [dataSource, setDataSource] = useState([]);
40343
40350
  const [indexFocus, setIndexFocus] = useState();
@@ -40368,46 +40375,83 @@ const SidebarSetColumn = (props) => {
40368
40375
  window.removeEventListener("resize", handleWindowResize);
40369
40376
  };
40370
40377
  }, []);
40378
+ const handleResetColumns = () => {
40379
+ if (resetDefaultColumns) {
40380
+ resetDefaultColumns();
40381
+ }
40382
+ handleSidebar();
40383
+ setDataSource([]);
40384
+ };
40371
40385
  const renderFooterButtons = () => {
40372
- return (jsxs(Fragment, { children: [jsx(Button$1, { color: "primary", onClick: handleSubmit, className: "me-1", children: t("Confirm") }), jsx(Button$1, { color: "secondary", onClick: handleCancel, outline: true, children: t("Close") })] }));
40386
+ return (jsxs(Fragment, { children: [resetDefaultColumns && jsx(Button$1, { color: "primary", onClick: () => messageBoxConfirm(t, handleResetColumns, {}, 'Do you want to reset the default settings?'), className: "me-1", children: t("Reset") }), jsx(Button$1, { color: "primary", onClick: handleSubmit, className: "me-1", children: t("Confirm") }), jsx(Button$1, { color: "secondary", onClick: handleCancel, outline: true, children: t("Close") })] }));
40373
40387
  };
40374
40388
  const visibleTemplate = (item, index) => {
40375
- return (jsx(Input$1, { defaultChecked: item.visible ?? true, disabled: item.invisibleDisable, type: "checkbox", style: { height: 18 }, className: " cursor-pointer", onChange: (e) => {
40389
+ return (jsx("div", { className: "r-cell-text", children: jsx(Input$1, { defaultChecked: item.visible ?? true, type: "checkbox", style: { height: 18 }, className: " cursor-pointer", onChange: (e) => {
40390
+ if (dataSource) {
40391
+ dataSource[index].visible = e.target.checked;
40392
+ setDataSource(dataSource);
40393
+ }
40394
+ } }) }));
40395
+ };
40396
+ const headerTextTemplate = (item, index) => {
40397
+ let textValue = t(item.headerText);
40398
+ return (jsx(Input$1, { defaultValue: textValue, className: classNames$2("border-0 rounded-0 input-element"), onChange: (e) => {
40399
+ textValue = e.target?.value;
40400
+ }, onBlur: () => {
40376
40401
  if (dataSource) {
40377
- dataSource[index].visible = e.target.checked;
40402
+ dataSource[index].headerText = textValue;
40378
40403
  setDataSource(dataSource);
40379
40404
  }
40380
40405
  } }));
40381
40406
  };
40382
40407
  const fixColumnTemplate = (item, index) => {
40383
- return (jsx(Input$1, { defaultChecked: item.fixedType === "left" || item.fixedType === "right", type: "checkbox", style: { height: 18 }, className: " cursor-pointer", onChange: (e) => {
40408
+ const optionsFix = [{ label: 'Trái', value: 'left' }, { label: 'Phải', value: 'right' }];
40409
+ return (jsx(SelectTable, { options: optionsFix, textAlign: "left", isClearable: true, onChange: (val) => {
40384
40410
  if (dataSource) {
40385
- if (e.target.checked) {
40386
- if (index * 2 <= dataSource.length) {
40387
- dataSource[index].fixedType = "left";
40388
- }
40389
- else {
40390
- dataSource[index].fixedType = "right";
40391
- }
40392
- }
40393
- else {
40394
- dataSource[index].fixedType = undefined;
40411
+ dataSource[index].fixedType = val?.value;
40412
+ setDataSource([...dataSource]);
40413
+ }
40414
+ }, value: item.fixedType ? optionsFix.find(x => x.value === item.fixedType) : undefined }));
40415
+ };
40416
+ const widthColumnTemplate = (item, index) => {
40417
+ const numericFormatProps = {
40418
+ value: !isNullOrUndefined(item.width) ? item.width.toString() : "",
40419
+ thousandSeparator: checkThousandSeparator(formatSetting?.thousandSeparator, formatSetting?.decimalSeparator),
40420
+ decimalSeparator: checkDecimalSeparator(formatSetting?.thousandSeparator, formatSetting?.decimalSeparator),
40421
+ allowNegative: false,
40422
+ decimalScale: 0
40423
+ };
40424
+ let floatValue = parseFloat(item.width ?? "0");
40425
+ return (jsx(NumericFormat, { style: { textAlign: 'right', height: 29 }, ...numericFormatProps, defaultValue: formartNumberic(item.width, formatSetting?.decimalSeparator ?? ",", formatSetting?.thousandSeparator ?? ".", 0), className: classNames$2("form-control border-0 rounded-0 input-numeric"), onValueChange: (values) => {
40426
+ floatValue = values?.floatValue;
40427
+ }, onFocus: (e) => {
40428
+ e.target.setSelectionRange(0, e.target.innerText.length - 1);
40429
+ }, onBlur: () => {
40430
+ if (floatValue !== item.width) {
40431
+ if (dataSource) {
40432
+ dataSource[index].width = !isNaN(floatValue) ? floatValue : 0;
40433
+ setDataSource(dataSource);
40395
40434
  }
40396
- setDataSource(dataSource);
40397
40435
  }
40398
40436
  } }));
40399
40437
  };
40400
40438
  const columns = [
40439
+ {
40440
+ field: "",
40441
+ headerText: "STT",
40442
+ template: (row, index) => {
40443
+ return index + 1;
40444
+ },
40445
+ textAlign: 'center',
40446
+ visible: true,
40447
+ width: 50
40448
+ },
40401
40449
  {
40402
40450
  field: "headerText",
40403
40451
  headerText: "Column name",
40404
- template: (e) => {
40405
- return jsx(Fragment$1, { children: t(e.headerText) });
40406
- },
40452
+ template: headerTextTemplate,
40407
40453
  visible: true,
40408
- width: 175,
40409
- maxWidth: 200,
40410
- minWidth: 150
40454
+ width: 200
40411
40455
  },
40412
40456
  {
40413
40457
  field: "",
@@ -40415,9 +40459,7 @@ const SidebarSetColumn = (props) => {
40415
40459
  headerText: "Display",
40416
40460
  textAlign: "center",
40417
40461
  visible: true,
40418
- width: 100,
40419
- maxWidth: 120,
40420
- minWidth: 80
40462
+ width: 80
40421
40463
  },
40422
40464
  {
40423
40465
  field: "",
@@ -40425,18 +40467,15 @@ const SidebarSetColumn = (props) => {
40425
40467
  headerText: "Fix the column",
40426
40468
  textAlign: "center",
40427
40469
  visible: true,
40428
- width: 100,
40429
- maxWidth: 120,
40430
- minWidth: 80
40470
+ width: 80
40431
40471
  },
40432
40472
  {
40433
40473
  field: "width",
40434
40474
  headerText: "Column width",
40435
40475
  textAlign: "right",
40436
40476
  visible: true,
40437
- width: 100,
40438
- maxWidth: 120,
40439
- minWidth: 80
40477
+ template: widthColumnTemplate,
40478
+ width: 100
40440
40479
  }
40441
40480
  ];
40442
40481
  const renderHeaderCol = (col, indexCol) => {
@@ -40454,10 +40493,6 @@ const SidebarSetColumn = (props) => {
40454
40493
  return renderHeaderCol(col, index);
40455
40494
  }) }) }), jsx("tbody", { className: "r-gridcontent", children: dataSource?.map((row, indexRow) => {
40456
40495
  return (jsx("tr", { className: classNames$2("r-row", { "last-row": indexRow === dataSource.length - 1 }, { "fisrt-row": indexRow === 0 }), children: columns.map((col, indexCol) => {
40457
- let value = row[col.field];
40458
- if (col.type === "numeric" || (col.typeCondition && col.typeCondition(row) === "numeric")) {
40459
- value = formartNumberic(row[col.field], ",", ".", col.numericSettings?.fraction, true) ?? 0;
40460
- }
40461
40496
  return (jsx(Fragment, { children: col.visible !== false && (jsx("td", { className: classNames$2(`r-rowcell fix-${col.fixedType}`, { "cell-fixed": col.fixedType }, { "r-active": indexFocus === indexRow }), style: {
40462
40497
  padding: 0,
40463
40498
  textAlign: col.textAlign ? col.textAlign : "left"
@@ -40475,7 +40510,7 @@ const SidebarSetColumn = (props) => {
40475
40510
  }
40476
40511
  }, children: jsx("div", { className: classNames$2("r-rowcell-div"), style: {
40477
40512
  width: col.fixedType ? Number(col.maxWidth ? col.maxWidth : col.width ? col.width : col.minWidth ?? "auto") : "auto"
40478
- }, children: jsx("div", { className: classNames$2("r-rowcell-content"), children: jsx("div", { className: "r-cell-text", children: col.template ? col.template(row, indexRow) : value }) }) }) }, `col-${indexRow}-${indexCol}`)) }, indexCol));
40513
+ }, children: jsx("div", { className: classNames$2("r-rowcell-content"), children: col.template && col.template(row, indexRow) }) }) }, `col-${indexRow}-${indexCol}`)) }, indexCol));
40479
40514
  }) }, `row-${indexRow}`));
40480
40515
  }) })] }) }) }) }), jsx("div", { className: "d-flex justify-content-end p-1 ", style: { boxShadow: "0 4px 24px 0 rgb(34 41 47 / 10%)" }, children: renderFooterButtons() })] }));
40481
40516
  };
@@ -42807,7 +42842,7 @@ const ToolbarBottom = ({ handleAdd, handleDuplicate, handleInsertBefore, handleI
42807
42842
 
42808
42843
  const TableEdit = forwardRef((props, ref) => {
42809
42844
  const { t } = useTranslation();
42810
- const { idTable, dataSource, columns, pagingSetting, setDataSource, height, maxHeight, minHeight, defaultValue, toolbarSetting, searchSetting, selectedItem, selectEnable, editDisable, addDisable, buttonSetting, formatSetting, haveSum, isMulti, disableAutoKey, commandClick, dataSourceChange, rowChange, setSelectedItem, handleSelect, onDuplicate, saveSettingColumn, allowFilter = true, allowOrder, settingColumns, optionsFilter } = props;
42845
+ const { idTable, dataSource, columns, pagingSetting, setDataSource, height, maxHeight, minHeight, defaultValue, toolbarSetting, searchSetting, selectedItem, selectEnable, editDisable, addDisable, buttonSetting, formatSetting, haveSum, isMulti, disableAutoKey, commandClick, dataSourceChange, rowChange, setSelectedItem, handleSelect, onDuplicate, saveSettingColumn, allowFilter = true, allowOrder, settingColumns, optionsFilter, resetDefaultColumns } = props;
42811
42846
  useImperativeHandle(ref, () => {
42812
42847
  return {
42813
42848
  refeshFocusRow: handleRefeshRow
@@ -42820,7 +42855,6 @@ const TableEdit = forwardRef((props, ref) => {
42820
42855
  const [searchTerm, setSearchTerm] = useState("");
42821
42856
  const [orderBy, setOrderBy] = useState([]);
42822
42857
  const [filterBy, setFilterBy] = useState([]);
42823
- const [refreshColumns, setRefreshColumns] = useState(false);
42824
42858
  const tableElement = useRef(null);
42825
42859
  const gridRef = useRef(null);
42826
42860
  const totalCount = dataSource.length;
@@ -42835,7 +42869,7 @@ const TableEdit = forwardRef((props, ref) => {
42835
42869
  }, [dataSource]);
42836
42870
  const { levels: headerColumns, flat: contentColumns, flatVisble, objWidthFixLeft, objWidthFixRight, lastObjWidthFixLeft, fisrtObjWidthFixRight, objHeaderWidthFixLeft, objHeaderWidthFixRight, indexFirstEdit: indexFirstEdit, indexLastEdit: indexLastEdit } = useMemo(() => {
42837
42871
  return calculateTableStructure(columns, settingColumns);
42838
- }, [columns, settingColumns, refreshColumns]);
42872
+ }, [columns, settingColumns]);
42839
42873
  const handleRefeshRow = () => {
42840
42874
  setRefreshRow(true);
42841
42875
  setTimeout(() => {
@@ -43104,15 +43138,27 @@ const TableEdit = forwardRef((props, ref) => {
43104
43138
  }
43105
43139
  } }));
43106
43140
  default:
43107
- return (jsx(Input$1, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, style: { textAlign: col.textAlign, height: 29 }, value: isNullOrUndefined(row[col.field]) ? "" : row[col.field], className: classNames$2("border-0 rounded-0 input-element", { "is-invalid": col.validate && col.validate(row[col.field], row) }), onChange: (val) => {
43108
- if (row[col.field] != val.target?.value) {
43109
- row[col.field] = val.target?.value;
43141
+ let textValue = row[col.field] ?? '';
43142
+ return (jsx(Input$1, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, style: { textAlign: col.textAlign, height: 29 }, defaultValue: textValue, className: classNames$2("border-0 rounded-0 input-element", { "is-invalid": col.validate && col.validate(row[col.field], row) }), onChange: (val) => {
43143
+ textValue = val.target?.value;
43144
+ }, onBlur: () => {
43145
+ if (row[col.field] != textValue) {
43146
+ row[col.field] = textValue;
43110
43147
  if (col.callback) {
43111
- col.callback(val.target.value, indexRow, row);
43148
+ col.callback(textValue, indexRow, row);
43112
43149
  }
43113
43150
  handleDataChange(row, col, indexRow);
43114
43151
  }
43115
43152
  }, onKeyDown: (e) => {
43153
+ if (e.key === "ArrowDown" || e.key === "NumpadEnter" || e.key === "ArrowUp" || e.key === "Enter" || e.key === "Tab") {
43154
+ if (row[col.field] != textValue) {
43155
+ row[col.field] = textValue;
43156
+ if (col.callback) {
43157
+ col.callback(textValue, indexRow, row);
43158
+ }
43159
+ handleDataChange(row, col, indexRow);
43160
+ }
43161
+ }
43116
43162
  checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
43117
43163
  }, onPaste: (e) => {
43118
43164
  if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable && !col.disablePaste) {
@@ -43674,15 +43720,9 @@ const TableEdit = forwardRef((props, ref) => {
43674
43720
  }, changeOrder: (val) => {
43675
43721
  setOrderBy([...val]);
43676
43722
  }, columns: contentColumns, setColumns: (newColumns) => {
43677
- newColumns.forEach((x) => {
43678
- const column = columns.find((y) => y.field === x.field);
43679
- if (column) {
43680
- column.visible = x.visible;
43681
- column.fixedType = x.fixedType;
43682
- column.width = x.width;
43683
- }
43684
- });
43685
- setRefreshColumns(!refreshColumns);
43723
+ if (saveSettingColumn) {
43724
+ saveSettingColumn(newColumns.map((x) => ({ field: x.field, headerText: x.headerText, visible: x.visible, fixedType: x.fixedType, width: x.width })));
43725
+ }
43686
43726
  }, fisrtObjWidthFixRight: fisrtObjWidthFixRight, lastObjWidthFixLeft: lastObjWidthFixLeft, totalCount: totalCount }, `header-${indexParent}-${index}`));
43687
43727
  }) }, `header-${-indexParent}`));
43688
43728
  }) }), jsx("tbody", { className: "r-gridcontent", role: "rowgroup", children: dataSource.map((row, indexRow) => {
@@ -43707,20 +43747,10 @@ const TableEdit = forwardRef((props, ref) => {
43707
43747
  handleDeleteAll(t, messageBoxConfirmDelete, setIndexFocus, changeDataSource, editDisable, addDisable, toolbarSetting, buttonSetting);
43708
43748
  }, setOpenPopupSetupColumn: setOpenPopupSetupColumn, indexFocus: indexFocus, editDisable: editDisable, addDisable: addDisable, buttonSetting: buttonSetting, toolbarSetting: toolbarSetting, headerColumns: headerColumns, t: t }))] }), pagingSetting?.allowPaging ? (jsx(PagingComponent, { onChangePage: onChangePage, pageSize: pagingSetting?.pageSize ?? 0, currentPage: pagingSetting?.currentPage ?? 0, pageOptions: pagingSetting?.pageOptions ?? [20, 30, 50, 100], totalItem: pagingClient ? totalCount : pagingSetting?.totalItem ?? 0, onChangePageSize: onChangePageSize })) : (jsx(Fragment$1, {}))] }), jsx(SidebarSetColumn, { handleSidebar: () => {
43709
43749
  setOpenPopupSetupColumn(!openPopupSetupColumn);
43710
- }, openSidebar: openPopupSetupColumn, column: [...contentColumns], setColumn: (newColumns) => {
43750
+ }, openSidebar: openPopupSetupColumn, column: [...contentColumns], resetDefaultColumns: resetDefaultColumns, setColumn: (newColumns) => {
43711
43751
  if (saveSettingColumn) {
43712
- console.log(newColumns);
43713
43752
  saveSettingColumn(newColumns.map((x) => ({ field: x.field, headerText: x.headerText, visible: x.visible, fixedType: x.fixedType, width: x.width })));
43714
43753
  }
43715
- newColumns.forEach((x) => {
43716
- const column = columns.find((y) => y.field === x.field);
43717
- if (column) {
43718
- column.visible = x.visible;
43719
- column.fixedType = x.fixedType;
43720
- column.width = x.width;
43721
- }
43722
- });
43723
- setRefreshColumns(!refreshColumns);
43724
43754
  } })] }));
43725
43755
  });
43726
43756