简体   繁体   中英

Simple pagination for Meteor and ReactJS

I have this code,

renderMsg(){
    return this.props.msgList.map((item) => {
            return (
                <tr key={item._id} id={item._id} className={(item.status == "unread")? "unread":""}>
                      <td className="inbox-small-cells">
                          <input type="checkbox" className="mail-checkbox" />
                      </td>
                  </tr>
            );

    });
}

I would like to add pagination for this renderMsg function. This function will output list of table rows.

So for example, this function will display only first 50. then the user can select the next page. then it will display number 51- 100 of the list.

How can I make it?

Put the currentPageIndex into the your component state and slice your array before mapping it. Assuming you use a 0 based index:

const { currentPage } = this.state;
const { msgList, pageSize } = this.props;
msgList
  .slice(currentPage * pageSize, (currentPage + 1) * pageSize)
  .map(item => ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM