material-react-table 2.11.0 → 2.11.1
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.esm.js +19 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +19 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/inputs/MRT_SelectCheckbox.tsx +2 -2
- package/src/utils/row.utils.ts +23 -6
package/package.json
CHANGED
@@ -129,8 +129,8 @@ export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
|
|
129
129
|
) : (
|
130
130
|
<Checkbox
|
131
131
|
indeterminate={
|
132
|
-
selectAll
|
133
|
-
? table.getIsSomeRowsSelected()
|
132
|
+
!isChecked && selectAll
|
133
|
+
? table.getIsSomeRowsSelected()
|
134
134
|
: row?.getIsSomeSelected() && row.getCanSelectSubRows()
|
135
135
|
}
|
136
136
|
{...commonProps}
|
package/src/utils/row.utils.ts
CHANGED
@@ -152,6 +152,7 @@ export const getMRT_RowSelectionHandler =
|
|
152
152
|
options: {
|
153
153
|
enableBatchRowSelection,
|
154
154
|
enableRowPinning,
|
155
|
+
manualPagination,
|
155
156
|
rowPinningDisplayMode,
|
156
157
|
},
|
157
158
|
refs: { lastSelectedRowId: lastSelectedRowId },
|
@@ -160,12 +161,14 @@ export const getMRT_RowSelectionHandler =
|
|
160
161
|
pagination: { pageIndex, pageSize },
|
161
162
|
} = getState();
|
162
163
|
|
163
|
-
const
|
164
|
+
const paginationOffset = manualPagination ? 0 : pageSize * pageIndex;
|
165
|
+
|
166
|
+
const isCurrentRowChecked = getIsRowSelected({ row, table });
|
164
167
|
|
165
168
|
const isStickySelection =
|
166
169
|
enableRowPinning && rowPinningDisplayMode?.includes('select');
|
167
170
|
|
168
|
-
// toggle
|
171
|
+
// toggle selection of this row
|
169
172
|
row.getToggleSelectedHandler()(event);
|
170
173
|
|
171
174
|
// if shift key is pressed, select all rows between last selected and this one
|
@@ -175,20 +178,34 @@ export const getMRT_RowSelectionHandler =
|
|
175
178
|
lastSelectedRowId.current !== null
|
176
179
|
) {
|
177
180
|
const rows = getMRT_Rows(table, undefined, true);
|
181
|
+
|
178
182
|
const lastIndex = rows.findIndex(
|
179
183
|
(r) => r.id === lastSelectedRowId.current,
|
180
184
|
);
|
185
|
+
|
181
186
|
if (lastIndex !== -1) {
|
182
|
-
const
|
187
|
+
const isLastIndexChecked = getIsRowSelected({
|
188
|
+
row: rows?.[lastIndex],
|
189
|
+
table,
|
190
|
+
});
|
191
|
+
|
192
|
+
const currentIndex = staticRowIndex + paginationOffset;
|
183
193
|
const [start, end] =
|
184
194
|
lastIndex < currentIndex
|
185
195
|
? [lastIndex, currentIndex]
|
186
196
|
: [currentIndex, lastIndex];
|
187
|
-
|
188
|
-
|
197
|
+
|
198
|
+
// toggle selection of all rows between last selected and this one
|
199
|
+
// but only if the last selected row is not the same as the current one
|
200
|
+
if (isCurrentRowChecked !== isLastIndexChecked) {
|
201
|
+
for (let i = start; i <= end; i++) {
|
202
|
+
rows[i].toggleSelected(!isCurrentRowChecked);
|
203
|
+
}
|
189
204
|
}
|
190
205
|
}
|
191
206
|
}
|
207
|
+
|
208
|
+
// record the last selected row id
|
192
209
|
lastSelectedRowId.current = row.id;
|
193
210
|
|
194
211
|
// if all sub rows were selected, unselect them
|
@@ -198,7 +215,7 @@ export const getMRT_RowSelectionHandler =
|
|
198
215
|
|
199
216
|
if (isStickySelection) {
|
200
217
|
row.pin(
|
201
|
-
!row.getIsPinned() &&
|
218
|
+
!row.getIsPinned() && isCurrentRowChecked
|
202
219
|
? rowPinningDisplayMode?.includes('bottom')
|
203
220
|
? 'bottom'
|
204
221
|
: 'top'
|