Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Row selection not working correctly when used with pagination and remote fetch in MRT v2 #433

Closed
1 task done
wizard22-cc opened this issue Nov 4, 2024 · 3 comments
Closed
1 task done
Labels
bug Something isn't working V2 Issue with MRT V2

Comments

@wizard22-cc
Copy link

mantine-react-table version

2.0.0-beta.7

react & react-dom versions

18.3.1

Describe the bug and the steps to reproduce it

I am using pagination on Mantine MRT table, with data being remotely fetched. The table is working fine and its displaying data correctly with pagination.
Now, I am trying to add row selection and some action buttons.
The issue is selected rows(using table.getSelectedRowModel()) are correctly fetched only for current page.
For example: If I select 2 rows from page 1, go to page 2 and select another row. table.getSelectedRowModel() is only returning record for current page(Page 2).

Same issue happens when you click on "clear selection", it only clears selection of current page.
The issue also exists in MRT's official example:
https://v2.mantine-react-table.com/docs/examples/remote

Below is my table config:

const [pagination, setPagination] = useState<MRT_PaginationState>({
  pageIndex: 0,
  pageSize: 10,
});
const table = useMantineReactTable({
    columns,
    data,
    enableStickyHeader: true,
    enableColumnActions: false,
    enableColumnFilters: false,
    enablePagination: true,
    enableSorting: false,
    enableTopToolbar: true,
    enableRowSelection: true,
    getRowId: (originalRow) => originalRow.sku,
    paginationDisplayMode: "pages",
    manualPagination: true,
    onPaginationChange: setPagination,
    rowCount: totalRecordCount.data ?? 0,
    renderTopToolbarCustomActions: ({ table }) => (
      <Box
        style={{
          display: "flex",
          gap: "16px",
          padding: "8px",
          flexWrap: "wrap",
        }}
      >
        <Button
          leftSection={<IconSpeakerphone />}
          variant="filled"
          disabled={!table.getIsSomeRowsSelected()}
          onClick={() => {
            handleProduct(table);
          }}
        >
          Process Product
        </Button>
      </Box>
    ),
    state: {
      pagination
    },
  });

function handleProduct(table: MRT_TableInstance<Product>) {
  table.getSelectedRowModel().flatRows.map((row) => {
    alert("processing " + row.getValue("name"));
    console.log("processing " + row.getValue("name"));
  });
}

Steps:
Bug 1:

  1. Create a table with remote fetch and manual pagination. Example: https://v2.mantine-react-table.com/docs/examples/react-query
  2. Enable row selection
  3. Select 1 row from Page 1
  4. Select 1 row from Page 2
  5. Use table.getSelectedRowModel() to get all selected rows(in my case on button click)

Expected Behaviour: 2 Selected rows from both pages should be returned
Actual Behaviour: Only selected row of current page is returned

Bug 2:
6. Click on "Clear selection"

Expected Behaviour: All selections from all pages should be cleared
Actual Behaviour: Only selections of current page is cleared

Minimal, Reproducible Example - (Optional, but Recommended)

Steps:
Bug 1:

  1. Create a table with remote fetch and manual pagination. Example: https://v2.mantine-react-table.com/docs/examples/react-query
  2. Enable row selection
  3. Select 1 row from Page 1
  4. Select 1 row from Page 2
  5. Use table.getSelectedRowModel() to get all selected rows(in my case on button click)

Expected Behaviour: 2 Selected rows from both pages should be returned
Actual Behaviour: Only selected row of current page is returned

Bug 2:
6. Click on "Clear selection"

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

None

Terms

  • I understand that if my bug cannot be reliably reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
@alessandrojcm alessandrojcm added bug Something isn't working V2 Issue with MRT V2 labels Nov 4, 2024
@thenick775-TST
Copy link

thenick775-TST commented Dec 3, 2024

I am seeing the same, but without remote fetching/pagination

@alessandrojcm
Copy link
Collaborator

alessandrojcm commented Dec 10, 2024

I am seeing the same, but without remote fetching/pagination

@thenick775-TST Can you please post an issue with your case? Because in the case of OP, with remote pagination, this is expected behaviour. But with uncontrolled pagination, we should take a look into it.

@wizard22-cc OP This is expected behaviour for manual pagination. The selection is being lost simply because the rows you selected are not in memory, as you changed pages. If you want to keep the selection between pages, you need to handle the selection state manually.

@thenick775-TST
Copy link

thenick775-TST commented Dec 16, 2024

@alessandrojcm I misinterpreted how this was supposed to function, I was doing a combination of client side manual filtering of the data (mimicking remote filtering , along with client side filtering in the table).

I realized a bit too late I needed to do either one or the other, or manage all filtering myself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working V2 Issue with MRT V2
Projects
None yet
Development

No branches or pull requests

3 participants