question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to show all rows with pagination overriding

See original GitHub issue

How to show all rows with pagination overriding

What to achieve

I want to have the option to set pageSize to ‘All’ to match to total count of rows in material-table.

What I have done

I use useState to create rowsPerPage , and set rowsPerPage in the handleChangeRowsPerPage function. I use component overriding to customize the Pagination and pass rowsPerPage and handler to its props. I also pass rowsPerPage to MaterialTable’s pageSize option.

Problems I encounter

The page does not re-size, and the state.pageSize does not update. Even though the props.options.pageSize and Pagination successfully update with onChangeRowsPerPage.

Link to sandbox

const handleChangeRowsPerPage = event => {
    //enable to set rows per page to match total count
    event.target.value === "All"
      ? setRowsPerPage(data.length)
      : setRowsPerPage(event.target.value);
  }; 

  const data = [
    { name: "Mehmet", surname: "Baran", birthYear: 1987 },
    { name: "Zerya Betül", surname: "Baran", birthYear: 2017 }
  ];
  return (
    <MaterialTable
      title="Component Override Demo"
      columns={[
        { title: "Name", field: "name" },
        { title: "Surname", field: "surname" },
        { title: "Birth Year", field: "birthYear" }
      ]}
      data={data}
      //options.pageSize updates, but no re-size
      options={{ pageSize: rowsPerPage }}
      // onChangeRowsPerPage={handleChangeRowsPerPage} //TypeError Cannot read property 'value' of undefined
      components={{
        Pagination: props => (
          <TablePagination
            {...props}
            rowsPerPageOptions={[5, 10, 20, "All"]}
            rowsPerPage={rowsPerPage}
            //updates pagination, but no re-size
            onChangeRowsPerPage={handleChangeRowsPerPage}
          />
        )
      }}
    />
  );
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ifndefdeadmau5commented, May 17, 2021

Please re-open this issue as I’m having a same problem which there’s no way to set pageSize programmatically

1reaction
kevheykcommented, Jun 19, 2020

@NAkibRUET Thank you for reply! Yes, I confirmed that onChangeRowsPerPage as a props of MaterialTable takes event value as parameter. Now I am able to call my own handler inside onChangeRowsPerPage as

              onChangeRowsPerPage={(value) => {
                // map 'All' to count
                if (value === 'All') {
                  value = products.length;
                }
               // missing something here to modify the pageSize state.

The problem persists because I cannot modify the pageSize state of MaterialTable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

my JavaFX TableView Pagination keep displaying all rows
My JavaFX table display pagination buttons number correctly but it keep displaying all rows,while I set the rows limit to 100, it detect...
Read more >
Control pagination - Microsoft Support
If you are not in print layout view, on the View menu, click Print Layout. Do any of the following: Keep lines together....
Read more >
Deferred loading of data - DataTables example
This automatic Ajax call to get the first page of data can be overridden by using the deferLoading initialisation property. It serves two...
Read more >
Using material-table in React to build feature-rich data tables
To achieve this, the MaterialTable component takes an additional parameter named components where you can override almost any part of the table.
Read more >
I am overriding the default pagination of MaterialTable as ...
However, the table always shows 5 rows even though the ... /56214292/any-example-for-custom-pagination-in-material-table-and-reactjs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found