rodloboz
Masu (枡, the squares of a grid) is tables for Phoenix. It is a data grid for LiveView that draws only the rows on the screen, so a hundred rows and a hundred thousand scroll the same way.
You give it a list, or an Ecto query and your repo. With Ecto, a sort is an ORDER BY, a filter and the search a WHERE, and the grid reads only the rows the person sees, a block of a hundred at a time.
<.data_grid id="customers" source={Customer} repo={Repo} searchable>
<:col field={:name} />
<:col field={:plan} type={:enum} />
<:col field={:revenue} type={:decimal} />
<:col field={:signed_up} type={:date} />
</.data_grid>
Filters, sorting and search
A filter menu on each column, with the filters of its type. An enum lists its values with their counts, from one GROUP BY. The filters show as chips above the grid. Shift+click sorts by several columns.
Editing, as in a spreadsheet
Give the grid your changeset and the cells edit: type on a cell, Enter and Tab, paste from a spreadsheet, fill down, undo. The edits save through Repo.update, and the changeset’s errors go on their cells.
Live, and together
live={{MyApp.PubSub, "orders"}} shows the rows that change on a topic as they change, in each person’s order and filters. Add Presence and the people who have the grid open see each other: their avatars, their cells in their colors, and a lock on the cell someone types in.
Groups, trees and details
group_by groups the rows with counts and totals, counted by the database. tree={:parent_id} shows rows as a tree. A :detail slot opens a row on any HEEx under it, another grid too.
And more
A menu on each cell with your own items, the keyboard of a spreadsheet, ⌘C that copies a range as a spreadsheet pastes it, CSV and XLSX export, saved views, locale formats from Intl, dark mode, and the WAI-ARIA grid pattern. Masu.Test reads, sorts and filters a grid in Phoenix.LiveViewTest with no browser.
Install
Masu needs Elixir 1.18, Phoenix 1.7.14 or 1.8, and LiveView 1.1. The
JavaScript is a prebuilt bundle in the Hex package, so your app does not
need Node.js for it.
{:masu, "~> 0.1"}
mix deps.get
mix masu.install
- Hex: masu | Hex
- Docs: Masu v0.1.1 — Documentation
- GitHub: GitHub - hattoriai/masu · GitHub
To try every feature, clone the repository and run mix dev.
Feedback and issues are welcome.
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #elixirconf-us
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance



















Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
brightball
Could this work to browse a very large data set, like something from Snowflake (via SnowflakeEx — snowflake_elixir v0.2.0)
Also, for the use of ORDER BY that you mentioned, that can get dangerous on big tables. LIMIT, OFFSET and ORDER BY all require pulling all of the data in scope into database memory for it to perform the sort, then get the data back. The bigger the table, the more intense this operation gets. If you hit an amount of data that is bigger than the DB will allow in memory, it will write a temp table to perform the operation and spike your disk I/O.
This write up gives a solid explanation of how to solve it, which should actually be pretty easy to implement in the structure that you’re using here. You essentially let the WHERE clause specify exactly where to start from and approximately where to end so that the amount of data being sorted is closer to what’s actually displayed and most importantly…consistent. If you’re sorting by column C then when you scroll to load the next set of data you know exactly the last data point in column C that was displayed. You’ll have to guess a little on the end point but you get the idea.
rodloboz
1/ Thanks for this, and for the link! It pushed me to look hard at how Masu pages, and to benchmark it to its limits. Masu 0.2.0 is out with what we found.
2/ Masu already used the seek method from that article: the next block starts after the sort values of the last row, with the primary key as a tiebreak. But the benchmarks showed that our WHERE kept Postgres from using the index. Fixed in 0.2.
3/ At 10M rows, a block in the middle now takes 0.24 ms (it was 450 ms), and the same block sorted by an indexed date takes 4 ms (it was 12.9 s). Numbers: masu/bench/RESULTS.md at main · hattoriai/masu · GitHub
4/ On ORDER BY: with an index on the sort column and the primary key, ORDER BY … LIMIT doesn’t sort the table. The database walks the index and stops. A deep OFFSET is the costly part, and that’s what keyset paging avoids. Without an index, a sort still scans, so index what people sort by.
5/ Snowflake: yes, with a source of your own (Masu.Source): run the query once and page through its result. The Ecto adapter for SnowflakeEx is archived, so I’d go through the driver or Snowflake’s SQL API.
6/ Or a controlled grid (on_query): your app runs the queries, and Masu is only the view. That’s how Lotus uses it, behind a flag: GitHub - elixir-lotus/lotus_web at try-masu · GitHub
7/ Also new in 0.2: count_limit for “10,000+” counts, and read={…} to page an Ecto source your own way.
pjode
looks great. Out of curiosity, is this something one would use over Flop if that is what they were using Flop for? Or in conjunction with it? And admittedly I only glanced at the docs but if that answer is the former, is there a means for more complex columns, such as tags, or in other words a many-to-1 relationship with the row?
rodloboz
Thanks! To be honest, I did not know about Flop when I built Masu. I wanted a grid that matches our other open source libraries: Kotoba, Jumon and Koyomi. They all have a similar visual style, and I use all of them in Lotus BI. I wanted to make something that is useful for the community, and that I can also change quickly when I need something new.
Instead of Flop or with Flop?
For a table in a LiveView, Masu does the work that you use Flop for, so you can use it in place of Flop. With an Ecto source (source={query} repo={Repo}), Masu makes the query itself. A sort becomes an ORDER BY. A filter or the search becomes a WHERE. Each block of rows is a LIMIT, and Masu reads it by key, not by OFFSET. Masu checks each filter against the column’s type on the server. It can also keep the view (sorts, filters, search) in the URL.
You can also use Masu together with Flop. If you already have Flop queries and want to keep them, use a controlled grid (on_query). The grid then does not sort, filter or page the rows. It sends you a %Masu.Query{} with the sorts and filters of the person, and an offset and a limit. You run your own query, for example with Flop, and give the grid the rows and the total. Masu has no adapter for Flop, so you write the small mapping from Masu.Query to Flop params.
Tags and other “has many” columns
You can show them now. Put a preload in the source query, and use a :col with your own HEEx, for example a chip for each tag. But in the Ecto source, only a column that names a field of the query’s first source can sort and filter in the database. A column of preloaded or joined data shows its values, but it does not sort or filter.
Thus “filter by tag” is not built in. To be honest, I did not think about it yet. Today you can do it in these ways:
All ideas are welcome. If you open an issue with your case, I will be happy to look at it. A PR is also welcome.
xNikhil001
Thanks for the great library. Fits right when and where we needed it.
effinbanjos
This looks very promising, well done.