@insticc/react-datagrid-2 1.0.23 → 1.0.25

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.
@@ -125,15 +125,41 @@ var DataGrid = function DataGrid(_ref) {
125
125
  return row;
126
126
  });
127
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]);
128
144
  (0, _react.useEffect)(function () {
129
145
  if (hasSubRows) {
130
146
  if (Object.keys(rowSelection).length > 0) {
131
147
  selectData(getSelectedRows(rowSelection));
132
148
  }
133
149
  } else {
134
- selectData(table.getSelectedRowModel().rows.map(function (row) {
135
- return row.original;
136
- }));
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);
137
163
  }
138
164
  }, [rowSelection]);
139
165
  (0, _react.useEffect)(function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insticc/react-datagrid-2",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "scripts": {