wlminimal

wlminimal

How to execute js function in Drab Commander

What I am doing is this

  1. In Analytics page, I display Chart using Chart.js and stats.
  2. There is 1 chart and 1 stat displayed, but when an user clicks "stat"button in order list, I want to update stat and chart in the page.

So in step 2. I did it to update stats(just simple number) using defhandler. and it updated assigns value so I can see a stat. but chart doesn’t update. because I need to execute Analytics.buildChart() again to update a chart.

That was imported and executed in app.js like this

import AnalyticsChart from "./analytics-chart"
let chartElement = document.getElementById("analyticsChart");
chartElement && AnalyticsChart.buildChart();

So I tried in same defhandler like this.

defhandler show_stats(socket, sender) do
# some code here

poke socket,
            total_sent: total_sent,
            deilvered_count: deilvered_count,
            undelivered_count: undelivered_count,
            total_clicks: total_clicks,
            recent_order: order

socket |> exec_js("AnalyticsChart.buildChart()")

end

And as I expected It doesn’t work.

So how can I do this?

Thanks in advance.

Most Liked

grych

grych

Creator of Drab

Cool, so it should work. Updating the “data-” attribute should update the dataset property as well. You may check it in the console with:

document.getElementById("total-sent").dataset.totalSent

after doing the poke. You just need to find a way to run the update chart function.

wlminimal

wlminimal

Yes, I just found a way to run the update chart function and did it like this in defhandler

socket |> exec_js!("AnalyticsChart.update()")

and it worked.
Thanks!

grych

grych

Creator of Drab

The better docs for scripts are here.

Where Next?

Popular in Questions Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
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
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
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

We're in Beta

About us Mission Statement