admin管理员组文章数量:1391947
I am adding a component which has a material-ui select (or dropdown) where a user a can jump to a page on pagination table or a table that has lots of rows, but only shows 20 rows at a time.
Now the component renders and it shows a drop down list of pages, but if you select page, the table doesn't change, and for the sake of me, I don't know why.
The below is the relevent bit my code for the Select component:
export const SelectaPage={{ pages, currentPage, onPageChange}}=>{
const handleChange =(event)=>{
onPageChange(event.target.value);
};
return(
<FormControl variant="outlined" fullWidth>
<Select
labelId="DropDown"
value={currentPage}
onChange={handleChange}>
{Array.from({length:pages}, (_,index)=>(
<MenuItem key={index+1} value={index+1}>
Page {index+1}
</MenuItem>
))}
</Select>
</FormControl>
);
}
On the component where the above is used it is like this:
const [currentPage, setCurrentPage] = useState(1)
const pages = Math.ceil(data.length/pageSize //this is the number of rows per page to be shown
const handlePageChange =(page)=>{
setCurrentPage(page);
};
const pagedData = data.slice((Number(currentPage)-1*pageSize, Number(currentPage)*pageSize);
.......
<TableBody {...getTableBodyProps()}>
{
pagedData.map(row=>{
return (
<TableRow row{row}
prepareRow=(prepareRow}
/>
);
})
}
....
The component for the dropdown is
<SelectPage
pages={pages}
currentPage={currentPage}
onPageChange={handlePageChange}
/>
Can someone please direct on how to fix this?
本文标签: reactjsReact MaterialUI Select for Jumping to Page on Table not workingStack Overflow
版权声明:本文标题:reactjs - React Material-UI Select for Jumping to Page on Table not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744697600a2620374.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论