@dooherceg/material-react-table 4.1.3 → 4.1.4
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 +32 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -18122,6 +18122,38 @@ const MaterialReactServerTableInstanceComponent = ({
|
|
|
18122
18122
|
// Lets any code that already has `table` (row actions, deleteRowsFn/editRowFn,
|
|
18123
18123
|
// custom cell renderers, etc.) trigger a manual reload without needing a ref.
|
|
18124
18124
|
table.refetch = refetch;
|
|
18125
|
+
|
|
18126
|
+
// addRow() only inserts the row into the local, page-capped `rows` state
|
|
18127
|
+
// (tableCrudFns.ts) — it never touches the server-driven `rowCount` this
|
|
18128
|
+
// component owns. Without this, pagination controls (Next button, page
|
|
18129
|
+
// count) stay stuck on the pre-add total until the next real fetch. Bump
|
|
18130
|
+
// rowCount here instead of forcing an immediate refetch: the consumer may
|
|
18131
|
+
// never navigate to the next page, so paying for a network round trip up
|
|
18132
|
+
// front isn't worth it — the real page 2 data still comes from an actual
|
|
18133
|
+
// fetch (triggered by fetchTrigger.pagination) once the user clicks Next.
|
|
18134
|
+
const baseAddRow = table.addRow;
|
|
18135
|
+
table.addRow = rowInput => {
|
|
18136
|
+
baseAddRow(rowInput);
|
|
18137
|
+
const addedCount = Array.isArray(rowInput) ? rowInput.length : 1;
|
|
18138
|
+
setRowCount(prev => prev + addedCount);
|
|
18139
|
+
};
|
|
18140
|
+
|
|
18141
|
+
// upsertRow() is the other row-creation entry point consumers actually use
|
|
18142
|
+
// (e.g. a "save" handler shared by both create and edit forms) — it needs
|
|
18143
|
+
// the same rowCount bump as addRow(), but only for rows that are genuinely
|
|
18144
|
+
// new. An upsert whose id already exists locally is an edit, not a growth
|
|
18145
|
+
// of the total row count, so only count ids NOT in the current row model
|
|
18146
|
+
// before delegating to the base handler (which does the real insert/merge).
|
|
18147
|
+
const baseUpsertRow = table.upsertRow;
|
|
18148
|
+
table.upsertRow = rowInput_0 => {
|
|
18149
|
+
const rowsToUpsert = Array.isArray(rowInput_0) ? rowInput_0 : [rowInput_0];
|
|
18150
|
+
const existingRowsById = table.getRowModel().rowsById;
|
|
18151
|
+
const insertedCount = rowsToUpsert.filter(row => !(row.id in existingRowsById)).length;
|
|
18152
|
+
baseUpsertRow(rowInput_0);
|
|
18153
|
+
if (insertedCount > 0) {
|
|
18154
|
+
setRowCount(prev_0 => prev_0 + insertedCount);
|
|
18155
|
+
}
|
|
18156
|
+
};
|
|
18125
18157
|
const fetchData = useCallback(async tableInstance => {
|
|
18126
18158
|
setIsLoading(true);
|
|
18127
18159
|
try {
|