@insticc/react-datagrid-2 1.0.22 → 1.0.24

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.
@@ -78,7 +78,9 @@ var DataGrid = function DataGrid(_ref) {
78
78
  _ref$enablePagination = _ref.enablePagination,
79
79
  enablePagination = _ref$enablePagination === void 0 ? true : _ref$enablePagination,
80
80
  _ref$enableVirtualiza = _ref.enableVirtualization,
81
- enableVirtualization = _ref$enableVirtualiza === void 0 ? false : _ref$enableVirtualiza;
81
+ enableVirtualization = _ref$enableVirtualiza === void 0 ? false : _ref$enableVirtualiza,
82
+ _ref$gridHeight = _ref.gridHeight,
83
+ gridHeight = _ref$gridHeight === void 0 ? 600 : _ref$gridHeight;
82
84
  var _useState = (0, _react.useState)(selectedIds.reduce(function (a, v) {
83
85
  return _objectSpread(_objectSpread({}, a), {}, _defineProperty({}, v, true));
84
86
  }, {})),
@@ -123,15 +125,41 @@ var DataGrid = function DataGrid(_ref) {
123
125
  return row;
124
126
  });
125
127
  };
128
+
129
+ // implemented to update selectedIds when props change
130
+ (0, _react.useEffect)(function () {
131
+ var currentSelectionIds = Object.keys(rowSelection);
132
+ // Check if the lengths are different or if any `selectedIds` are not in `rowSelection`
133
+ var isSelectionOutOfSync = selectedIds.length !== currentSelectionIds.length || selectedIds.some(function (id) {
134
+ return !rowSelection[id];
135
+ });
136
+ if (isSelectionOutOfSync) {
137
+ var newSelection = selectedIds.reduce(function (acc, id) {
138
+ acc[id] = true; // Set true for each id in selectedIds
139
+ return acc;
140
+ }, {});
141
+ setRowSelection(newSelection);
142
+ }
143
+ }, [selectedIds]);
126
144
  (0, _react.useEffect)(function () {
127
145
  if (hasSubRows) {
128
146
  if (Object.keys(rowSelection).length > 0) {
129
147
  selectData(getSelectedRows(rowSelection));
130
148
  }
131
149
  } else {
132
- selectData(table.getSelectedRowModel().rows.map(function (row) {
133
- return row.original;
134
- }));
150
+ // DEPRECATED:
151
+ // selectData(table.getSelectedRowModel().rows.map(row => row.original));
152
+
153
+ var selectedRowIds = Object.keys(table.getState().rowSelection);
154
+ var selectedRows = selectedRowIds.map(function (rowId) {
155
+ var matchingRow = table.getSelectedRowModel().rows.find(function (row) {
156
+ return "".concat(row.id) === rowId;
157
+ });
158
+ return matchingRow ? matchingRow.original : null; // Return original if found
159
+ }).filter(function (row) {
160
+ return row !== null;
161
+ }); // Filter out any null values
162
+ selectData(selectedRows);
135
163
  }
136
164
  }, [rowSelection]);
137
165
  (0, _react.useEffect)(function () {
@@ -399,7 +427,7 @@ var DataGrid = function DataGrid(_ref) {
399
427
  },
400
428
  muiTableContainerProps: {
401
429
  sx: {
402
- maxHeight: '600px'
430
+ maxHeight: gridHeight
403
431
  }
404
432
  },
405
433
  defaultDisplayColumn: {
@@ -552,7 +580,8 @@ DataGrid.propTypes = {
552
580
  enableFullScreenToggle: _propTypes["default"].bool,
553
581
  enableDensityToggle: _propTypes["default"].bool,
554
582
  enableGlobalFilter: _propTypes["default"].bool,
555
- enableVirtualization: _propTypes["default"].bool
583
+ enableVirtualization: _propTypes["default"].bool,
584
+ gridHeight: _propTypes["default"].oneOfType([_propTypes["default"].number, _propTypes["default"].string]) // defines the height of the grid content, can be a number like 600, or a string like '600px' or 'fit-content'
556
585
  };
557
586
  var _default = exports["default"] = DataGrid; // DataGrid.defaultProps = {
558
587
  // hasExcelExport: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insticc/react-datagrid-2",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "scripts": {