LoginSignup
11
11

More than 5 years have passed since last update.

ThinReportsのリストでページ内にあと何行追加できるか調べたい

Posted at

ThinReportsのリストでページ内にあと何行追加できるか調べたい

listにadd_rowで行を追加していくと、
ページに収まらなくなった場合にも自動的に改ページされて便利です。

ですが、複数行をひとかたまりとして追加して、
途中で改ページされたくない場合もあるかと思います。
(まとめて5行追加したいのに3行しか入らないとわかれば、その時点でpage_breakで改行したい)

そんな時はそのページにあと何行追加できるのか知りたくなります。

ソースを読んだところ、行を追加してページ内に収まらなくなったことを検出するメソッドoverflow?は見つかりましたが、あと何行追加できるか調べるメソッドは見つけられませんでした。

ということで自分でメソッドを作りました。

page.rb
module ThinReports
  module Core::Shape

    class List::Page < Basic::Interface
      def rest_row_count
        height = manager.current_page_state.height
        row_height = manager.current_page_state.format.section_height(:detail)
        max_height = manager.page_max_height
        row_count = (height / row_height).floor
        max_row_count = (max_height / row_height).floor
        max_row_count - row_count
      end
    end

  end
end

id = :detailsのリストオブジェクトの場合

page.list(:details).rest_row_count

でcurrent_pageに追加できる残り行数がわかります。

11
11
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
11
11