wlminimal
How to execute js function in Drab Commander
What I am doing is this
- In Analytics page, I display Chart using Chart.js and stats.
- 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
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
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
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








