Skip to content

How to encapsulate the Flop.Phoenix.table component? #86

Answered by woylie
MMore asked this question in Q&A
Discussion options

You must be logged in to vote

Hi other Mathias,

that's actually quite simple. Each named slot is available as a single assign, so you can just pass it on to another component.

The wrapper component:

def table_with_pagination(assigns) do
  ~H"""
  <div class="table-wrapper">
    <.Flop.Phoenix.table items={@items} meta={@meta} path_helper={@path_helper} col={@col} />
    <.Flop.Phoenix.pagination meta={@meta} path_helper={@path_helper} />
  </div>
  """
end

Using the wrapper component:

<.table_with_pagination
  items={@pets}
  meta={@meta}
  path_helper={{Routes, :pet_path, [@socket, :index]}}
>
  <:col let={p} label="ID" field={:id}><%= p.id %></:col>
  <:col let={p} label="Name" field={:name}><%= p.name %></:col>
</.t…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@MMore
Comment options

@MMore
Comment options

@woylie
Comment options

Answer selected by MMore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants