react-table-edit 1.4.39 → 1.4.41

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,12 +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
- if (column.fixedType) {
17699
+ if (column.fixedType !== undefined && column.fixedType !== null) {
17700
17700
  cell.fixedType = column.fixedType;
17701
17701
  }
17702
- if (column.width) {
17702
+ if (column.width !== undefined && column.width !== null) {
17703
17703
  cell.width = column.width;
17704
17704
  }
17705
+ if (column.headerText !== undefined && column.headerText !== null) {
17706
+ cell.headerText = column.headerText;
17707
+ }
17705
17708
  }
17706
17709
  else {
17707
17710
  cell.visible = false;
@@ -17709,24 +17712,24 @@ const calculateTableStructure = (columns, settingColumns) => {
17709
17712
  }
17710
17713
  levels[level].push(cell);
17711
17714
  const headerKey = `${level}-${indexCol}`;
17712
- if (col.fixedType === "left" && col.visible !== false) {
17715
+ if (cell.fixedType === "left" && cell.visible !== false) {
17713
17716
  objHeaderWidthFixLeft[headerKey] = leftTotal;
17714
17717
  }
17715
17718
  if (!hasChildren) {
17716
17719
  const index = flat.length;
17717
- const width = col.width ?? 40;
17720
+ const width = cell.width ?? 40;
17718
17721
  cell.index = index;
17719
17722
  flat.push(cell);
17720
- if (col.fixedType === "left" && col.visible !== false) {
17723
+ if (cell.fixedType === "left" && cell.visible !== false) {
17721
17724
  objWidthFixLeft[index] = leftTotal;
17722
17725
  leftTotal += width;
17723
17726
  }
17724
- if (col.fixedType === "right" && col.in !== false) {
17727
+ if (cell.fixedType === "right" && cell.visible !== false) {
17725
17728
  rightTotal -= width;
17726
17729
  objWidthFixRight[index] = rightTotal;
17727
17730
  }
17728
17731
  }
17729
- if (col.fixedType === "right" && col.visible !== false) {
17732
+ if (cell.fixedType === "right" && cell.visible !== false) {
17730
17733
  objHeaderWidthFixRight[headerKey] = rightTotal;
17731
17734
  }
17732
17735
  return colspanSum + colspan;
@@ -40341,7 +40344,7 @@ const Sidebar = (props) => {
40341
40344
  };
40342
40345
 
40343
40346
  const SidebarSetColumn = (props) => {
40344
- const { column, setColumn, openSidebar, handleSidebar } = props;
40347
+ const { column, setColumn, openSidebar, handleSidebar, resetDefaultColumns, formatSetting } = props;
40345
40348
  const { t } = useTranslation();
40346
40349
  const [dataSource, setDataSource] = useState([]);
40347
40350
  const [indexFocus, setIndexFocus] = useState();
@@ -40372,46 +40375,83 @@ const SidebarSetColumn = (props) => {
40372
40375
  window.removeEventListener("resize", handleWindowResize);
40373
40376
  };
40374
40377
  }, []);
40378
+ const handleResetColumns = () => {
40379
+ if (resetDefaultColumns) {
40380
+ resetDefaultColumns();
40381
+ }
40382
+ handleSidebar();
40383
+ setDataSource([]);
40384
+ };
40375
40385
  const renderFooterButtons = () => {
40376
- 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") })] }));
40377
40387
  };
40378
40388
  const visibleTemplate = (item, index) => {
40379
- 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: () => {
40380
40401
  if (dataSource) {
40381
- dataSource[index].visible = e.target.checked;
40402
+ dataSource[index].headerText = textValue;
40382
40403
  setDataSource(dataSource);
40383
40404
  }
40384
40405
  } }));
40385
40406
  };
40386
40407
  const fixColumnTemplate = (item, index) => {
40387
- 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) => {
40388
40410
  if (dataSource) {
40389
- if (e.target.checked) {
40390
- if (index * 2 <= dataSource.length) {
40391
- dataSource[index].fixedType = "left";
40392
- }
40393
- else {
40394
- dataSource[index].fixedType = "right";
40395
- }
40396
- }
40397
- else {
40398
- 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);
40399
40434
  }
40400
- setDataSource(dataSource);
40401
40435
  }
40402
40436
  } }));
40403
40437
  };
40404
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
+ },
40405
40449
  {
40406
40450
  field: "headerText",
40407
40451
  headerText: "Column name",
40408
- template: (e) => {
40409
- return jsx(Fragment$1, { children: t(e.headerText) });
40410
- },
40452
+ template: headerTextTemplate,
40411
40453
  visible: true,
40412
- width: 175,
40413
- maxWidth: 200,
40414
- minWidth: 150
40454
+ width: 200
40415
40455
  },
40416
40456
  {
40417
40457
  field: "",
@@ -40419,9 +40459,7 @@ const SidebarSetColumn = (props) => {
40419
40459
  headerText: "Display",
40420
40460
  textAlign: "center",
40421
40461
  visible: true,
40422
- width: 100,
40423
- maxWidth: 120,
40424
- minWidth: 80
40462
+ width: 80
40425
40463
  },
40426
40464
  {
40427
40465
  field: "",
@@ -40429,18 +40467,15 @@ const SidebarSetColumn = (props) => {
40429
40467
  headerText: "Fix the column",
40430
40468
  textAlign: "center",
40431
40469
  visible: true,
40432
- width: 100,
40433
- maxWidth: 120,
40434
- minWidth: 80
40470
+ width: 80
40435
40471
  },
40436
40472
  {
40437
40473
  field: "width",
40438
40474
  headerText: "Column width",
40439
40475
  textAlign: "right",
40440
40476
  visible: true,
40441
- width: 100,
40442
- maxWidth: 120,
40443
- minWidth: 80
40477
+ template: widthColumnTemplate,
40478
+ width: 100
40444
40479
  }
40445
40480
  ];
40446
40481
  const renderHeaderCol = (col, indexCol) => {
@@ -40458,10 +40493,6 @@ const SidebarSetColumn = (props) => {
40458
40493
  return renderHeaderCol(col, index);
40459
40494
  }) }) }), jsx("tbody", { className: "r-gridcontent", children: dataSource?.map((row, indexRow) => {
40460
40495
  return (jsx("tr", { className: classNames$2("r-row", { "last-row": indexRow === dataSource.length - 1 }, { "fisrt-row": indexRow === 0 }), children: columns.map((col, indexCol) => {
40461
- let value = row[col.field];
40462
- if (col.type === "numeric" || (col.typeCondition && col.typeCondition(row) === "numeric")) {
40463
- value = formartNumberic(row[col.field], ",", ".", col.numericSettings?.fraction, true) ?? 0;
40464
- }
40465
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: {
40466
40497
  padding: 0,
40467
40498
  textAlign: col.textAlign ? col.textAlign : "left"
@@ -40479,7 +40510,7 @@ const SidebarSetColumn = (props) => {
40479
40510
  }
40480
40511
  }, children: jsx("div", { className: classNames$2("r-rowcell-div"), style: {
40481
40512
  width: col.fixedType ? Number(col.maxWidth ? col.maxWidth : col.width ? col.width : col.minWidth ?? "auto") : "auto"
40482
- }, 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));
40483
40514
  }) }, `row-${indexRow}`));
40484
40515
  }) })] }) }) }) }), jsx("div", { className: "d-flex justify-content-end p-1 ", style: { boxShadow: "0 4px 24px 0 rgb(34 41 47 / 10%)" }, children: renderFooterButtons() })] }));
40485
40516
  };
@@ -42811,7 +42842,7 @@ const ToolbarBottom = ({ handleAdd, handleDuplicate, handleInsertBefore, handleI
42811
42842
 
42812
42843
  const TableEdit = forwardRef((props, ref) => {
42813
42844
  const { t } = useTranslation();
42814
- 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;
42815
42846
  useImperativeHandle(ref, () => {
42816
42847
  return {
42817
42848
  refeshFocusRow: handleRefeshRow
@@ -43107,15 +43138,27 @@ const TableEdit = forwardRef((props, ref) => {
43107
43138
  }
43108
43139
  } }));
43109
43140
  default:
43110
- 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) => {
43111
- if (row[col.field] != val.target?.value) {
43112
- 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;
43113
43147
  if (col.callback) {
43114
- col.callback(val.target.value, indexRow, row);
43148
+ col.callback(textValue, indexRow, row);
43115
43149
  }
43116
43150
  handleDataChange(row, col, indexRow);
43117
43151
  }
43118
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
+ }
43119
43162
  checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
43120
43163
  }, onPaste: (e) => {
43121
43164
  if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable && !col.disablePaste) {
@@ -43704,7 +43747,7 @@ const TableEdit = forwardRef((props, ref) => {
43704
43747
  handleDeleteAll(t, messageBoxConfirmDelete, setIndexFocus, changeDataSource, editDisable, addDisable, toolbarSetting, buttonSetting);
43705
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: () => {
43706
43749
  setOpenPopupSetupColumn(!openPopupSetupColumn);
43707
- }, openSidebar: openPopupSetupColumn, column: [...contentColumns], setColumn: (newColumns) => {
43750
+ }, openSidebar: openPopupSetupColumn, column: [...contentColumns], resetDefaultColumns: resetDefaultColumns, setColumn: (newColumns) => {
43708
43751
  if (saveSettingColumn) {
43709
43752
  saveSettingColumn(newColumns.map((x) => ({ field: x.field, headerText: x.headerText, visible: x.visible, fixedType: x.fixedType, width: x.width })));
43710
43753
  }