Skip to content

Expanding is not working with manualPagination and with truthy paginateExpandedRows #5110

Description

@BEGEMOT9I

Describe the bug

Hi! In the current project, we have two types of tables: controlled and independent. Both of them have the default options for pagination and for expanding:

const defaultOptions = {
  // We don't want to slice expanded rows
  paginateExpandedRows: false,
  getPaginationRowModel: getPaginationRowModel(),
  getExpandedRowModel: getExpandedRowModel(),
}

The controlled table can be customized by a developer, especially pagination (he can set manualPagination in true) if he doesn't want to use internal pagination. The other type of table might not be customizable and pagination is fully controlled by logic around the current library. So, in the first case, expanding functionality becomes broken when we are trying to use external pagination params and setting manualPagination in true. I've found that the course of the problem is here:
https://github.com/TanStack/table/blob/main/packages/table-core/src/utils/getExpandedRowModel.ts#L22

After that, I tried to fix it and just added a simple check to getExpandedRowModel:

function getCustomExpandedRowModel<TData extends RowData>(): (
  table: Table<TData>
) => () => RowModel<TData> {
  return table =>
    memo(
      () => [
        table.getState().expanded,
        table.getPreExpandedRowModel(),
        table.options.paginateExpandedRows,
        table.options.manualPagination,
      ],
      (expanded, rowModel, paginateExpandedRows, manualPagination) => {
        if (
          !rowModel.rows.length ||
          (expanded !== true && !Object.keys(expanded ?? {}).length)
        ) {
          return rowModel
        }

        // Here is the fix
        if (!paginateExpandedRows && !manualPagination) {
          // Only expand rows at this point if they are being paginated
          return rowModel
        }

        return expandRows(rowModel)
      },
      {
        key: 'getExpandedRowModel',
        debug: () => table.options.debugAll ?? table.options.debugTable,
      }
    )
}

It's also presented in an example. But for now, we have other options to avoid this problem:

  1. Don't use paginateExpandedRows in false with manualPagination
  2. Create a custom getExpandedRowModel and copy the internal logic from the repo
  3. Update somehow getExpandedRowModel and don't use paginateExpandedRows inside

I think, the first choice is the easiest one, but it must be documented (because it's very unclear). In other case, if the fix in the example is looking good for you, I can make a PR with tests)

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/dreamy-euler-fjgltr

Steps to reproduce

  1. Open an example
  2. Try to expand any row

Expected behavior

A row must be expanded

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Any

react-table version

v8.10.3

TypeScript version

No response

Additional context

No response

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions