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

Open
1 task done
wizard22-cc opened this issue Nov 4, 2024 · 0 comments
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
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

2 participants