Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 01:16
    ddnexus commented #279
  • 01:13
    ddnexus commented #279
  • Mar 04 13:40
    tosch commented #279
  • Mar 04 13:22
    tosch commented #279
  • Mar 04 10:29
    codecov[bot] commented #279
  • Mar 04 10:29
    codecov[bot] commented #279
  • Mar 04 10:29
    codecov[bot] commented #279
  • Mar 04 10:29
    codecov[bot] commented #279
  • Mar 04 10:29
    codecov[bot] commented #279
  • Mar 04 10:29
    codecov[bot] commented #279
  • Mar 04 10:29
    codecov[bot] commented #279
  • Mar 04 10:25
    codecov[bot] commented #279
  • Mar 04 10:25
    codecov[bot] commented #279
  • Mar 04 10:25
    tosch synchronize #279
  • Mar 04 10:24
    tosch commented #279
  • Mar 04 09:04
    ddnexus commented #279
  • Mar 04 08:57
    tosch commented #279
  • Mar 04 08:47
    ddnexus commented #279
  • Mar 04 08:38
    ddnexus commented #279
  • Mar 03 12:18
    codecov[bot] commented #279
Ben
@yosupgurl
$('#records_table').append("<%=j :partial => 'partials/gallery_items' %>"); $('#div_next_link').html("<%=j render :partial => 'partials/next_link' %>"); Pagy.init(document.getElementById('container')); like this?
Domizio Demichelis
@ddnexus
yes sir
Ben
@yosupgurl
sorry man, i'm just so confused. I've tried so many things at this point
Uncaught Error: Module build failed (from ./node_modules/rails-erb-loader/index.js): Error: rails-erb-loader failed with code: 1
Domizio Demichelis
@ddnexus
ok, so please, debug that first
but it's better you start new with the example or you will never get it done
Ben
@yosupgurl
Mhhm, i've created a separate app for debugging. My issue lies somewhere with the rails-erb-loader.
I can render .erb just not .erb partials in the JS.
Domizio Demichelis
@ddnexus
rails erb loader is part of webpack
Ben
@yosupgurl
thnx for the help though.
Domizio Demichelis
@ddnexus
replace the erb line wih the actual content to try
but add the export and global too
I will have time tomorrow. good luck
Nathan Elmore
@elmoren
Am I able to set the total count when calling pagy() manually? I'm using pagy with a handful of aggregations, and when I do order by aggregation, pagy's count query says that aggregation doesn't exist
I might just end up using Countless
Nathan Elmore
@elmoren
I found the info I needed in the "Paginate any Collection" of your docs. Sorry about that
andymilk
@andymilk
Is it possible to use pagy_countless with pagy_searchkick?
Domizio Demichelis
@ddnexus
pagy_searchkick gets the count from the searchkick results object that already contains the total_count, so pagy_countless is kind of pointless
Domizio Demichelis
@ddnexus
the total_count gets it from response["hits"]["total"], hence whatever is there, has already been fetched by the time pagy gets it. pagy does not query the DB: that's the reason it's pointless
andymilk
@andymilk
thanks!
Ben
@yosupgurl
hey, is there a way to retrieve the value for the current page? I'd like to display different content based on current page.
Domizio Demichelis
@ddnexus
@pagy.page
aykc
@aykc
Hi. I use pagy_url_for to make links like items/page/3, but trim extra doesn't work for this, I still have /page/1 in browser url. Without pagy_url_for it works fine. How to solve this problem? Thank you.
Domizio Demichelis
@ddnexus
Indeed the trim extra expects a query string param. You should take a look at the trim extra code and change the regular expression according to your custom url. It will be simpler than what the extra.
Nikita Pashinsky
@nikitapashinsky

hey! how could one add classes directly (inline) to the <%== link.call(item) %>, or the <%= item %>?

I'm using Tailwind and would like to keep utilities inline, and I want to style the link directly to make the click area bigger (using padding).

I was able to add classes to previous and next buttons as follows: <%== link.call(pagy.prev, "&lsaquo; Previous", 'class="p-4 ... "' %>, but I can't do the same with link.call(item).

Everything I write after item, for example: link.call(item, 'class="p-4"') is rendered directly on the page... Would appreciate your help. Thank you!

Domizio Demichelis
@ddnexus
You might be looking for this
1 reply
Tioneb12
@Tioneb12
How to keep consistent loop index across pages ?
owen-le-goldenowl
@owen-le-goldenowl
Hi! I'm using pagy_bootstrap_nav_js. Is there anyway to custom the template like pagy_bootstrap_nav? https://github.com/ddnexus/pagy/blob/master/lib/templates/bootstrap_nav.html.slim
    def pagy_bootstrap_nav_js(pagy, id=pagy_id)
      link, p_prev, p_next = pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next
      tags = { 'before' => p_prev ? %(<ul class="pagination"><li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
                                  : %(<ul class="pagination"><li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev')}</a></li>),
               'link'   => %(<li class="page-item">#{mark = link.call(PAGE_PLACEHOLDER)}</li>),
               'active' => %(<li class="page-item active">#{mark}</li>),
               'gap'    => %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap')}</a></li>),
               'after'  => p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li></ul>)
                                  : %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li></ul>) }
      %(<nav id="#{id}" class="pagy-bootstrap-nav-js" role="navigation" aria-label="pager"></nav>#{pagy_json_tag(:nav, id, tags, pagy.sequels, defined?(TRIM) && pagy.vars[:page_param])})
    end
checked the source code. Do i need to override this method?
Domizio Demichelis
@ddnexus
There is no template for the *_jshelpers. In theory you could write your own but it will be slower and more complex to write than just override the helper method, as you guessed.
potatosalad94
@potatosalad94

Hello everyone!
I'm building a watchlist app on rails, using Tmdb API.
Basically I'd like to search for movies, and have the results displaying 20 movies per page.
I'm also using the 'themoviedb-api' gem, which allows me to use the following in my controller (for exemple for Harry potter)

Tmdb::Search.movie("Harry Potter")

which will give back :

#<Tmdb::Result page=1, total_pages=23, total_results=446, results=[#<Tmdb::Movie adult=false, backdrop_path="/hziiv14OpD73u9gAak4XDDfBKa2.jpg", genre_ids=[12, 14], id=671, original_language="en", original_title="Harry Potter and the Philosopher's Stone", overview="Harry Potter has lived under the stairs at his aunt and uncle's house his whole life. But on his 11th birthday, he learns he's a powerful wizard -- with a place waiting for him at the Hogwarts School of Witchcraft and Wizardry. As he learns to harness his newfound powers with the help of the school's kindly headmaster, Harry uncovers the truth about his parents' deaths -- and about the villain who's to blame.", popularity=144.218, poster_path="/wuMc08IPKEatf9rnMNXvIDxqP4W.jpg", release_date="2001-11-16", title="Harry Potter and the Philosopher's Stone", video=false, vote_average=7.9, vote_count=19723>

So there are already the page, total_pages in the API answer, but I don't know how to exploit them.
I tried to do

@pagy, @movies = pagy(Tmdb::Search.movie(params[:query]))

But it seems to suits only for model saved in DB. In my case the Movies are API calls

Thanks

Domizio Demichelis
@ddnexus
Indeed, the pagyvanilla constructor is for AR collections. In case you have already the count and the current page, you have to do the inverse process.
Domizio Demichelis
@ddnexus
Something like:
tobj = Tmdb::Search.movie("Harry Potter")
@pagy = Pagy.new(count: tobj.total_results, page: tobj.page)
@movies = tobj.results
should mimic what the pagy constructor does
please, confirm whether that works, because if it does, I am going to add this very example to the doc
potatosalad94
@potatosalad94

I've tried it but it seems that @movies still shows the result array of the first page, no matter which page i'm accessing.
I also tried to use the Array Extra, by doing to following in my controller:

      movies = Tmdb::Search.movie(params[:query])
      @pagy_a, @movies = pagy_array(movies.results, count: movies.total_results, page: movies.page)

But the same is happening, always showing me the first page array

Domizio Demichelis
@ddnexus
that probably means that you don't use the page param for the search
potatosalad94
@potatosalad94
normally to access page 2 with the tmdb gem, it would be :
Tmdb::Search.movie(params[:query], page: 2)
Domizio Demichelis
@ddnexus
if you just do Tmdb::Search.movie("Harry Potter") again and again, you ar3e getting always the first page. How are you supposed to pass the page to Tmdb::Search?
so you have to do Tmdb::Search.movie(params[:query], page: params[:page])
Domizio Demichelis
@ddnexus
does that work?
potatosalad94
@potatosalad94
Yes ! Finally it worked ! No need for the Array Extra, your first solution was the one. Was just missing the page params. Thanks a lot :)
Domizio Demichelis
@ddnexus
great then... I will probably use the example in the documentation somewhere
Domizio Demichelis
@ddnexus
thank you
Andy Qin
@andylouisqin
hello all! I see that pagy handles overflow nicely, but what's the best way to configure "underflow" behavior, e.g. page < 1. I'd like it to return an empty page as well
Andy Qin
@andylouisqin
(I've answered my own question. Will be rescuing from this error)
Domizio Demichelis
@ddnexus
Yes Andy, here is another bit about handling exceptions. And if you are using rescue_from ArgumentError be aware of the gotcha at the end of the page.