artem

artem

Has anybody tried integrating an advanced JavaScript data grid with dynamic data fetch to Live View?

Hi all

The problem
I am into building a data intensive app in LiveView. It is basically a smart analyzer of customer feedback: use AI to parse out opinions and topics, then aggregate, chart, present it visually.

Naturally, a bit part of design is going to be a large data grid for the feedback topics, statements, various metadata (e.g. date or app version) with pagination or ideally even endless scrolling.

This seems to be a quite good fit for live view, some elixir courses even teach you how to build paginated grid in one of the first lessons.. yet it’s still would be a home grown solution.

Looking for a solution
It would be wonderful if I could use some of the advanced JS data grids out there such as AG-Grid or ReactTable. Then you’d be able to get for free a lot of battle-proven magic such as easy column reordering, filtering, UI for endless scrolling or unwrapping rows to details as in screenshot.

In theory if such grids could use some DOM nodes for data LiveView could relatively easily supply that when needed and adjust queries based on callbacks (e.g. when button for sorting is clicked), but that’s theory :slight_smile:

Has anybody done it in practice? Is it really possible to connect a JS-native data grid with lots of JS-side magic with a LiveView data supply?

Most Liked

sb8244

sb8244

Author of Real-Time Phoenix

Thanks for the shout-out. As a note I really liked the hybrid react+LiveView approach and would do it again.

I don’t feel any attachment to having a pure LV system. I’d rather pick the thing that’s going to work best for what I want, especially if I don’t need to create it from scratch.

LiveView hooks give you everything you need to mount react, so check out that post to see how I did it.

NduatiK

NduatiK

You can also have a look at Kino’s DataTable implementation. They use:

  1. LiveView to load the data - SmartCell
  2. React + Glide Data Grid to render out - JS

Looks good I think,


This Elixir + this React lets you update the rendered data

codeanpeace

codeanpeace

Off the top of my head, there’s no reason it wouldn’t be possible. LiveView Hooks make all sorts of integrations possible. The question, as always, becomes whether it’s the right thing to do given your unique set of circumstances i.e. requirements, constraints, and tradeoffs.

The LiveView docs are great and especially relevant is the section on DOM Patching & temporary assigns

A container can be marked with phx-update, allowing the DOM patch operations to avoid updating or removing portions of the LiveView, or to append or prepend the updates rather than replacing the existing contents. This is useful for client-side interop with existing libraries that do their own DOM operations.

The “ignore” behaviour is frequently used when you need to integrate with another JS library. Note only the element contents are ignored, its attributes can still be updated.

… as well as the section on JavaScript Interoperability.

There’s also a helpful article written by the author of Real-Time Phoenix @sb8244 React in LiveView: How and Why? that establishes some useful guidelines when working with React within LiveView.

And another potentially useful resource includes phoenix_live_react, a helper library for easily rendering React components within Phoenix LiveViews.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

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 record...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New

We're in Beta

About us Mission Statement