Rails, pagination of a matrix -
i have huge (in number of rows) matrix (double array) , paginate it, on first page first 10 elements seen.
example:
arraya = [["a",1,2,3],["b",5,7,8],["c",4,7,3],["d",1,2,9],["e",4,2,6]]
on first page first 2 elements of arraya
seen:
["a",1,2,3] ["b",5,7,8]
i not sure can standard will_paginate gem.
and how display in view? have following structure display matrix:
<% mat = @mat mat.each |line| %> <tr> <td> <% line.each |el|%> <td class ="table_column_width"> <%=el%> </td> <% end %> </td> </tr> <% end %>
will_paginate adds paginate
method onto array (see https://github.com/mislav/will_paginate/blob/master/lib/will_paginate/array.rb). may need require 'will_paginate/array'
if it's not available.
you should able
# controller... @results = arraya.paginate(page: 1, :per_page: 2) # view.... <% @results.each |letter, *numbers| %> <%= letter %> <% numbers.each |number| %> <%= number %> <% end %> <% end %>
Comments
Post a Comment