Cinder.Refresh (Cinder v0.9.0)
View SourceHelper functions for refreshing Cinder collection data from parent LiveViews.
This module provides convenient functions to refresh collection data after performing CRUD operations, ensuring the collection reflects the latest state without requiring a full page reload.
Usage
After performing operations that modify data displayed in a collection:
def handle_event("delete", %{"id" => id}, socket) do
MyApp.MyResource
|> Ash.get!(id)
|> Ash.destroy!()
{:noreply, refresh_table(socket, "my-table-id")}
endOr to refresh multiple collections:
def handle_event("bulk_delete", params, socket) do
# ... perform bulk operations ...
{:noreply, refresh_tables(socket, ["users-table", "orders-table"])}
endRefresh Behavior
When a collection is refreshed:
- Current filters are maintained
- Sort order is preserved
- Pagination state is kept (user stays on current page if possible)
- Loading state is shown during refresh
- Data is reloaded using the same query parameters
Summary
Functions
Refreshes a specific collection by its ID.
Sends a refresh message to the LiveComponent with the given ID. The collection will reload its data while maintaining current filters, sorting, and pagination state.
Parameters
socket- The LiveView socketcollection_id- The ID of the collection to refresh (string)
Returns
The socket (unchanged, but refresh message has been sent).
Examples
# Refresh a specific collection
{:noreply, refresh_table(socket, "users-table")}
# In a handle_event callback
def handle_event("delete_user", %{"id" => id}, socket) do
MyApp.User
|> Ash.get!(id)
|> Ash.destroy!()
{:noreply, refresh_table(socket, "users-table")}
end
Refreshes multiple collections by their IDs.
Convenience function to refresh several collections at once while maintaining granular control over which collections are refreshed.
Parameters
socket- The LiveView socketcollection_ids- List of collection IDs to refresh
Returns
The socket (unchanged, but refresh messages have been sent to all specified collections).
Examples
{:noreply, refresh_tables(socket, ["users-table", "orders-table"])}