qbs-react-grid 1.1.9 → 1.1.11

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.
@@ -129,14 +129,33 @@ var QbsTable = function QbsTable(_ref) {
129
129
  }
130
130
  }, [checkedKeys]);
131
131
  var handleToggle = useCallback(function (columnName) {
132
- setColumns(function (cols) {
133
- return cols.map(function (col) {
134
- return col.title === columnName ? _extends({}, col, {
132
+ var lastVisibleColumn = null;
133
+ var visibleCount = 0;
134
+ var updatedColumns = columns === null || columns === void 0 ? void 0 : columns.map(function (col) {
135
+ // Toggle visibility for the matched column
136
+ if (col.title === columnName) {
137
+ col = _extends({}, col, {
135
138
  isVisible: !col.isVisible
136
- }) : col;
137
- });
139
+ });
140
+ }
141
+ if (col.isVisible) {
142
+ lastVisibleColumn = col;
143
+ visibleCount++;
144
+ }
145
+ return col;
138
146
  });
139
- }, []);
147
+ if (visibleCount > 0 && lastVisibleColumn) {
148
+ updatedColumns.forEach(function (col) {
149
+ var _lastVisibleColumn;
150
+ if (col.field === ((_lastVisibleColumn = lastVisibleColumn) === null || _lastVisibleColumn === void 0 ? void 0 : _lastVisibleColumn.field)) {
151
+ col.resizable = false;
152
+ } else {
153
+ col.resizable = true;
154
+ }
155
+ });
156
+ }
157
+ setColumns(updatedColumns);
158
+ }, [columns]);
140
159
  var handleColumnWidth = useCallback(function (newWidth, dataKey) {
141
160
  if (newWidth === undefined || dataKey === undefined) return;
142
161
  setColumns(function (prevColumns) {
@@ -136,14 +136,33 @@ var QbsTable = function QbsTable(_ref) {
136
136
  }
137
137
  }, [checkedKeys]);
138
138
  var handleToggle = (0, _react.useCallback)(function (columnName) {
139
- setColumns(function (cols) {
140
- return cols.map(function (col) {
141
- return col.title === columnName ? (0, _extends2["default"])({}, col, {
139
+ var lastVisibleColumn = null;
140
+ var visibleCount = 0;
141
+ var updatedColumns = columns === null || columns === void 0 ? void 0 : columns.map(function (col) {
142
+ // Toggle visibility for the matched column
143
+ if (col.title === columnName) {
144
+ col = (0, _extends2["default"])({}, col, {
142
145
  isVisible: !col.isVisible
143
- }) : col;
144
- });
146
+ });
147
+ }
148
+ if (col.isVisible) {
149
+ lastVisibleColumn = col;
150
+ visibleCount++;
151
+ }
152
+ return col;
145
153
  });
146
- }, []);
154
+ if (visibleCount > 0 && lastVisibleColumn) {
155
+ updatedColumns.forEach(function (col) {
156
+ var _lastVisibleColumn;
157
+ if (col.field === ((_lastVisibleColumn = lastVisibleColumn) === null || _lastVisibleColumn === void 0 ? void 0 : _lastVisibleColumn.field)) {
158
+ col.resizable = false;
159
+ } else {
160
+ col.resizable = true;
161
+ }
162
+ });
163
+ }
164
+ setColumns(updatedColumns);
165
+ }, [columns]);
147
166
  var handleColumnWidth = (0, _react.useCallback)(function (newWidth, dataKey) {
148
167
  if (newWidth === undefined || dataKey === undefined) return;
149
168
  setColumns(function (prevColumns) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qbs-react-grid",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "A React table component",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -118,11 +118,39 @@ const QbsTable: React.FC<QbsTableProps> = ({
118
118
 
119
119
  [checkedKeys]
120
120
  );
121
- const handleToggle = useCallback((columnName: string) => {
122
- setColumns(cols =>
123
- cols.map(col => (col.title === columnName ? { ...col, isVisible: !col.isVisible } : col))
124
- );
125
- }, []);
121
+
122
+ const handleToggle = useCallback(
123
+ (columnName: string) => {
124
+ let lastVisibleColumn: any = null;
125
+ let visibleCount = 0;
126
+
127
+ const updatedColumns = columns?.map(col => {
128
+ // Toggle visibility for the matched column
129
+ if (col.title === columnName) {
130
+ col = { ...col, isVisible: !col.isVisible };
131
+ }
132
+ if (col.isVisible) {
133
+ lastVisibleColumn = col;
134
+ visibleCount++;
135
+ }
136
+
137
+ return col;
138
+ });
139
+
140
+ if (visibleCount > 0 && lastVisibleColumn) {
141
+ updatedColumns.forEach(col => {
142
+ if (col.field === lastVisibleColumn?.field) {
143
+ col.resizable = false;
144
+ } else {
145
+ col.resizable = true;
146
+ }
147
+ });
148
+ }
149
+
150
+ setColumns(updatedColumns);
151
+ },
152
+ [columns]
153
+ );
126
154
 
127
155
  const handleColumnWidth = useCallback((newWidth?: number, dataKey?: any) => {
128
156
  if (newWidth === undefined || dataKey === undefined) return;