app/helpers/spreadsheet_helper.rb
module SpreadsheetHelper
include Seek::Data::SpreadsheetExplorerRepresentation
def generate_paginate_rows(rows, sheet_index, per_page)
#need to record the index of the nil row, for later use
rows_with_index = []
rows = rows.drop(1) if rows.first.nil?
rows.each_with_index do |row, index|
if row.nil?
rows_with_index << Row.new(index+1)
else
rows_with_index << row
end
end
if sheet_index == params[:sheet].try(:to_i)
current_page = params[:page].try(:to_i) || 1
else
current_page = 1
end
WillPaginate::Collection.create(current_page, per_page, rows_with_index.count) do |pager|
start = (current_page-1)*per_page # assuming current_page is 1 based.
pager.replace(rows_with_index[start, per_page]) unless rows_with_index[start, per_page].nil?
end
end
end