Skip to Content
Building Table Views with Phoenix LiveView
book

Building Table Views with Phoenix LiveView

by Peter Ullrich
January 2023
Intermediate to advanced
67 pages
1h 42m
English
Pragmatic Bookshelf
Content preview from Building Table Views with Phoenix LiveView

Sorting with LiveComponent

As mentioned above, we want our LiveComponent to handle the user interactions, update the sorting parameters, and notify the LiveView about the changes. The SortingComponent that follows does just that. Open lib/meow_web/live/sorting_component.ex, and have a look at the module shown here. We’ll go through it step by step afterward.

 defmodule​ MeowWeb.MeerkatLive.SortingComponent ​do
 use​ MeowWeb, ​:live_component
 
 def​ render(assigns) ​do
 ~​H​"""
  <div phx-click="sort" phx-target={@myself} >
  <%= @key %> <%= chevron(@sorting, @key) %>
  </div>
  """
 end
 
 def​ handle_event(​"​​sort"​, _params, socket) ​do
  %{​sorting:​ %{​sort_dir:​ sort_dir}, ​key:​ key} = socket.assigns
 
  sort_dir ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Craft GraphQL APIs in Elixir with Absinthe

Craft GraphQL APIs in Elixir with Absinthe

Bruce Williams, Ben Wilson
Realm of Racket

Realm of Racket

Conrad Barski M.D., David Van Horn, Eight Students of Northeastern University, Matthias Felleisen
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9798888650097Errata Page