te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - How to add pagination to a long list using React MaterialUI? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to add pagination to a long list using React MaterialUI? - Stack Overflow

programmeradmin3浏览0评论

I am using react + materialUI for implementing a list and filter functionality. The list is expected to be populated from an Http request and can have large number of list items. So for this reason, I was looking into pagination in MaterialUI documentation but no clear implementation is there. I want to provide my list and hope the pagination ponent to break the data and show over multiple pages.

This is the link to materialUI ponent: /

Any help on how to proceed with this?

Picture of the List view.

Edit: I want to implement list item as a clickable ponent so that on click it redirects to the a list item specific dashboard.

Update: I've implemented it using the material-ui pagination ponent. Works fine!

Demo: =/demo.js

I am using react + materialUI for implementing a list and filter functionality. The list is expected to be populated from an Http request and can have large number of list items. So for this reason, I was looking into pagination in MaterialUI documentation but no clear implementation is there. I want to provide my list and hope the pagination ponent to break the data and show over multiple pages.

This is the link to materialUI ponent: https://material-ui./ponents/pagination/

Any help on how to proceed with this?

Picture of the List view.

Edit: I want to implement list item as a clickable ponent so that on click it redirects to the a list item specific dashboard.

Update: I've implemented it using the material-ui pagination ponent. Works fine!

Demo: https://codesandbox.io/s/material-demo-g0xo5?file=/demo.js

Share Improve this question edited May 20, 2020 at 20:28 Manu Sharma asked May 13, 2020 at 12:00 Manu SharmaManu Sharma 7641 gold badge8 silver badges23 bronze badges 6
  • Its like a table or list view? – nmanikumar5 Commented May 13, 2020 at 12:13
  • Its a List. I am getting an array in response and I am looping over it to generate <ListItem>s. I'm using material ponents. – Manu Sharma Commented May 13, 2020 at 12:16
  • I think you should decide how many item should be showed on 1 page and store a page number in your state, then show items that should show in that page. Like yourItemList.subarray(((pageNumber - 1)*(numberOfItemsForPage)), ((pageNumber)*(numberOfItemsForPage))) – acbay Commented May 13, 2020 at 12:17
  • Yeah, that's what I would be doing, but I think angular material has a paginator ponent and I thought that must be the case with react material too and I'm missing something here. – Manu Sharma Commented May 13, 2020 at 12:38
  • 2 Thanks for the code sandbox ! – ShashankAC Commented Jun 29, 2020 at 12:04
 |  Show 1 more ment

2 Answers 2

Reset to default 6

I think you should decide how many item should be showed on 1 page and store a page number in your state, then show items that should show in that page. Like yourItemList.subarray(((pageNumber - 1)*(numberOfItemsForPage)), ((pageNumber)*(numberOfItemsForPage) - 1)) You can bine this with material ui pagination, should work fine!

I recently dealt with this issue with the following snippet (consider that my example required handling a plex object):

<Pagination count={data.sub.length%10===0 ? data.sub.length/10 : data.sub.length/10 +1} page={page} onChange={(event,val)=> setPage(val)}  />

For my example I wanted 10 items rendered per page (hence the division by 10) and I calculated whether there would be trailing elements that should be rendered using the modulo and ternary operators. Following this, presenting a reference to the current page and hook to change the current page will achieve the desired result. Remember that what is most relevant is the amount of elements rendered at each page on the DOM.

发布评论

评论列表(0)

  1. 暂无评论