Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active Admin pagination

Active Admin's pagination on index pages is great, but we are trying to allow the user to type in the desired page number (in addition to the clickable page buttons).

Their desire is to have a prompt like "Enter Page Number:" and an input box where they can type in the desired page number.

Anyone done this already, or have ideas on how to proceed?

like image 481
user3101149 Avatar asked Aug 15 '26 04:08

user3101149


1 Answers

You can create a custom sidebar section like this:

sidebar :jump_to_page do
  input :page_number
  input type: :submit
end

Then add this to you active_admin.js.coffee file:

$ ->
  $("#page_number_submit").on 'click', (e) ->
    page_number = $("#page_number").val()

    if window.location.search.indexOf("page=") > 0
      window.location.search = window.location.search.replace(/page=\d*/, "page=#{page_number}")
    else if window.location.search.indexOf("?") == 0
      window.location.search = window.location.search + "&page=#{page_number}"
    else
      window.location.search = "page=#{page_number}"
like image 61
Timo Schilling Avatar answered Aug 18 '26 18:08

Timo Schilling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!