lucca65

lucca65

Paginate when I have two tables in the same page

Hey!

I have a liveview page that holds two flop tables. Everything works well with filters, as I’m using on_change for my filter_form and that works great. I’m able to keep an assign for each of my table filters.

The problem is that I don’t have this kind of mechanism for pagination, where I can push events (instead of changing the querystring params). Query strings would be nice to have, but is there a way for me to paginate both tables independently? Maybe I’m missing something?

Most Liked

redrapids

redrapids

Author of Adopting Elixir

After working with this library for a bit, I wholeheartedly recommend it. I love that everything is done through navigation links, so the whole browser experience on the liveview page is wonderful. There are lots of options to hook everything we need. Thanks for your time on this.

woylie

woylie

I think you have two options here.

Option 1: Add a separate form for that control and add an event handler similar to:

def handle_event("set-page-size", %{"page_size" => page_size}, socket) do
    flop = %{socket.assigns.meta.flop | page_size: page_size}
    path = Flop.Phoenix.build_path(~p"/entities", flop)
    {:noreply, push_patch(socket, to: path)}
  end

Or if you don’t care about having the filter parameters in the URL, query the data right there.

Option 2: The filter_fields component renders a hidden input for the page size. You should be able to place a page size input after filter_fields. If we adapt the example from the readme, it might look something like this:

  ~H"""
  <.form
    for={@form}
    id={@id}
    phx-target={@target}
    phx-change={@on_change}
    phx-submit={@on_change}
  >
    <.filter_fields :let={i} form={@form} fields={@fields}>
      <.input
        field={i.field}
        label={i.label}
        type={i.type}
        phx-debounce={120}
        {i.rest}
      />
    </.filter_fields>
    
    <input type="text" name="page_size" value={@meta.page_size} />

    <button class="button" name="reset">reset</button>
  </.form>
  """
redrapids

redrapids

Author of Adopting Elixir

That worked flawlessly. I took the first option, but the second would work for some designs. Would you like a PR for documentation of this feature, or no? Particularly, the build_path and the right place to hook custom filter fields were hard to find.

Last Post!

woylie

woylie

A PR would be appreciated!

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement