Fork me on GitHub
#re-frame
<
2020-06-25
>
rberger06:06:00

Any examples of the re-frame way to have a datatable like view of potentially large (more than you would want to cache locally) data coming from a server. The view would have options that would allow for sorting and searching which would happen on the server causing the page data in the browser to be refreshed. More interested in how to handle the fetching/paging into the re-frame app-db and how to orchestrate it all rather than the views themselves, though that would be good too. Thanks for any tips or pointers to examples!

jkrasnay11:06:03

I’ve implemented a pretty full-featured data table in my app. Unfortunately I can’t share the code but I can describe the basic principles.

jkrasnay11:06:24

I’ve broken it down into three pieces of data.

jkrasnay11:06:31

First I have what I call the “model”. It contains the URL of the endpoint that can fetch me a page of data and data about how to render each column. Next is the “view state”, which contains things the user can change: sort column and order, page size, current page index, etc. Finally, there’s the “content” that comes back from the endpoint, which contains the row data for the current page and a count of the total number of rows.

jkrasnay11:06:14

I put the model in a CLJC file and the other two in app DB. I made the decision to only have one data table per page so that my data is always at a known path, which simplifies all my event handlers.

jkrasnay11:06:46

For each data table in my app I create an endpoint that accepts the view state and returns a new content structure. I just POST the view state, but you could just as well serialize the state into a query parameter and do a GET.

jkrasnay11:06:50

I pass the model to the view component. It subscribes to the view state and content and renders accordingly.

jkrasnay11:06:36

When I first display a page containing a data table, I dispatch the event that posts to my endpoint and populates the content slot on successful return.

jkrasnay11:06:50

When the user interacts with the data table, e.g. clicking a header to change the sort order or clicking to view the next page, I dispatch an event to update the view state, then re-do the call to the endpoint to refresh the content.

jkrasnay11:06:13

That’s the essence of it. You can add stuff around that, e.g. showing a spinner while data is being loaded, adding filters to your view state, etc., but it’s all just expanding on those ideas.

jkrasnay11:06:35

Hope this helps.

🙏 3
rberger20:06:48

@U0DTSCAUU Thanks for the info. Will chew on that. We’re using graphql/aws appsync for the backend, but it sounds like the style you are describing should work similarly.

rberger20:06:56

Would still love to see code on how others have approached this in re-frame

p-himik08:06:07

For some reason, GitHub says that the latest release is v0.10.7.

mikethompson23:06:47

@p-himik where in GitHub are you seeing this version? Perhaps in the README, via a clojars badge?

p-himik06:06:58

The main GitHub page of the project:

mikethompson12:06:43

Thanks, i created an issue. We'll fix it.