I've accomplished to change the pageSize based on my live resizable container: It works well until I change page.
Once I change page, if I reduce the height of the container, the height of the table can't go lower then the height when I changed the page.
In other words when I change the page (from page 1 to page 2 for example), let's say the height is 360px with ~12 rows, if I go higher the 360px rows are "added" smoothly, but when I go under 360px, the height of the table doesn't change anymore.
NOTE: before changing the page everything works smoothly.
export default class Table extends React.Component {
constructor() {
...
}
componentWillReceiveProps(newProps) {
if (this.props.y != newProps.y) {
// size row
let rowHeight = 32.88;
// size resizable panel
let panelHeight = newProps.y;
// size of the extra y of the table (header + footer)
let extraTable = 27 + (this.props.x < 650 ? 75 : 45);
// setting pageSize of the table
this.setState({pageSize: parseInt((panelHeight - extraTable) / rowHeight)});
}
}
render() {
return (
<ReactTable
data={this.props.data}
columns={this.props.columns}
pageSize={this.state.pageSize}
/>
)
}
}
On Github it's been told me that this is an implementation issue but I feel like it can be a work around. Does anybody have an idea how to do this?
React-table needs data in array format and columns also in array format. Columns take at minimum Header and accessor as column definitions. Here Header is the display name given to the column of the table and accessor is the key in the data (used for mapping column to the matching data).
const useTable = (data, page, rowsPerPage) => { // ... }; export default useTable; Then we will have two states, one will be the range of our table that will be the pages and the second will be the slice of the elements of the current page. // @/src/hooks/useTable. js import { useState, useEffect } from "react"; // ...
Solved by using the defaultPageSize instead of pageSize, and changing the key of the component to force re-render (based on the pageSize itself):
render() {
return (
<ReactTable
key={this.state.pageSize}
data={this.data}
columns={this.columns}
defaultPageSize={this.state.pageSize}
showPageSizeOptions={false}
/>
)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With