MishkaGervaz.Table.Web.Events.SelectionHandler behaviour
(MishkaGervaz v0.0.1-alpha.2)
Copy Markdown
View Source
Handles selection operations for Events module.
This module provides functions for managing row selection state, including individual selection, select-all, and clear selection.
Customization
You can create a custom SelectionHandler:
defmodule MyApp.CustomSelectionHandler do
use MishkaGervaz.Table.Web.Events.SelectionHandler
# Custom toggle that limits selection to 10 items
def toggle_select(state, id) do
if MapSet.size(state.selected_ids) >= 10 and
not MapSet.member?(state.selected_ids, id) do
{:error, :max_selection_reached}
else
super(state, id)
end
end
endThen configure it in your resource's DSL:
mishka_gervaz do
table do
events do
selection MyApp.CustomSelectionHandler
end
end
endSee MishkaGervaz.Table.Web.Events,
MishkaGervaz.Table.Web.State,
and the sibling handlers SanitizationHandler, RecordHandler,
BulkActionHandler, HookRunner, RelationFilterHandler.
Summary
Callbacks
Clears all selection state.
Returns the effective selected IDs for bulk actions.
Toggles selection for a single row.
Toggles select-all state.
Types
@type state() :: MishkaGervaz.Table.Web.State.t()
Callbacks
Clears all selection state.
Resets select_all?, selected_ids, and excluded_ids.
Returns the updated state.
Returns the effective selected IDs for bulk actions.
Returns one of:
list()- List of selected IDs:all- All items selected{:all_except, list()}- All items except the excluded ones
Toggles selection for a single row.
When select_all? is true, toggles the ID in excluded_ids.
When select_all? is false, toggles the ID in selected_ids.
Returns the updated state.
Toggles select-all state.
Resets both selected_ids and excluded_ids when toggling.
Returns the updated state.