12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

React.jsでpaginationを生成するモジュールを作りました

Last updated at Posted at 2015-06-10

同じようなものを短期間に2つ作ったので、共通部分を切り出してみました。
https://github.com/toshi0383/ts-react-pager

使い方は、こんな感じ。

var Pager = require('ts-react-pager').Pager
var YourApp = React.createClass({
  handlePaging: function(pageNum) {
    this.setState({data:this.state.data, currentPage:pageNum})
  },
  render: function() {
    var o = {
      dataLength:this.props.data.length,  // Your data's length.
      handler: this.handlePaging,         // Gets called when page is changed. You must implement your own. Otherwise crashes.
      pageSize: this.props.pageSize,      // Max display count of your data.
      currentPage: this.state.currentPage // Your current page should be set in your state.
    }
    var pager = (<Pager object={o}>)
    return (
      <div>
        {pager}
        {yourtable}
        {pager}
      </div>
    )
  }
})

こうなる

ss.png

テーブルは、共通化してもあまり綺麗に書けるようにならない気がするので、各自描画するということで。
似たようなライブラリは既にたくさんあるんですが、React.jsのことがよくわかってない状態で人のものを使いたくないと思い、自作してしまいました。

npm moduleをpublishするの初めてでしたが、package.jsonを書いてnpm publish だけよくてお手軽でした。

12
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?