Skip to content

Action Definitions

Actions are operations that can be performed on table data There are 3 types of actions: bulk actions, table actions, and row actions.

  1. Bulk Actions: Actions that can be performed on multiple selected rows. Selected rows are passed to the action callback, allowing for operations on multiple items at once.
  2. Table Actions: Actions that can be performed on the table as a whole. It doesn't have an access to the row data, so it's typically used for operations that affect the entire table, e.g. cleaning the table data.
  3. Row Actions: Actions that can be performed on individual rows. These actions are acce

Each action callback returns an ActionHandlerResult object, below you can see its definition:

ActionHandlerResult

Bases: TypedDict

Represents the result of an action handler.

ATTRIBUTE DESCRIPTION
success

Indicates whether the action was successful.

TYPE: bool

error

(Optional) Error message if the action failed.

TYPE: NotRequired[str | None]

redirect

(Optional) URL to redirect to after the action.

TYPE: NotRequired[str | None]

message

(Optional) Informational message about the action result.

TYPE: NotRequired[str | None]

Source code in ckanext/tables/types.py
18
19
20
21
22
23
24
25
26
27
28
29
30
class ActionHandlerResult(TypedDict):
    """Represents the result of an action handler.

    Attributes:
        success: Indicates whether the action was successful.
        error: (Optional) Error message if the action failed.
        redirect: (Optional) URL to redirect to after the action.
        message: (Optional) Informational message about the action result.
    """
    success: bool
    error: NotRequired[str | None]
    redirect: NotRequired[str | None]
    message: NotRequired[str | None]

BulkActionDefinition dataclass

Defines an action that can be performed on multiple rows.

ATTRIBUTE DESCRIPTION
action

Unique identifier for the action.

TYPE: str

label

Display label for the action.

TYPE: str

callback

Function to be called when the action is triggered.

TYPE: Callable[[list[Row]], ActionHandlerResult]

icon

(Optional) Icon class for the action.

TYPE: str | None

Source code in ckanext/tables/table.py
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
@dataclass(frozen=True)
class BulkActionDefinition:
    """Defines an action that can be performed on multiple rows.

    Attributes:
        action: Unique identifier for the action.
        label: Display label for the action.
        callback: Function to be called when the action is triggered.
        icon: (Optional) Icon class for the action.
    """

    action: str
    label: str
    callback: Callable[[list[types.Row]], types.ActionHandlerResult]
    icon: str | None = None

    def __call__(self, rows: list[types.Row]) -> types.ActionHandlerResult:
        return self.callback(rows)

TableActionDefinition dataclass

Defines an action that can be performed on the table itself.

ATTRIBUTE DESCRIPTION
action

Unique identifier for the action.

TYPE: str

label

Display label for the action.

TYPE: str

callback

Function to be called when the action is triggered.

TYPE: Callable[..., ActionHandlerResult]

icon

(Optional) Icon class for the action.

TYPE: str | None

Source code in ckanext/tables/table.py
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
@dataclass(frozen=True)
class TableActionDefinition:
    """Defines an action that can be performed on the table itself.

    Attributes:
        action: Unique identifier for the action.
        label: Display label for the action.
        callback: Function to be called when the action is triggered.
        icon: (Optional) Icon class for the action.
    """

    action: str
    label: str
    callback: Callable[..., types.ActionHandlerResult]
    icon: str | None = None

    def __call__(self) -> types.ActionHandlerResult:
        return self.callback()

RowActionDefinition dataclass

Defines an action that can be performed on a row.

ATTRIBUTE DESCRIPTION
action

Unique identifier for the action.

TYPE: str

label

Display label for the action.

TYPE: str

callback

Function to be called when the action is triggered.

TYPE: Callable[[Row], ActionHandlerResult]

icon

(Optional) Icon class for the action.

TYPE: str | None

with_confirmation

(Optional) Whether to show a confirmation dialog before executing the action.

TYPE: bool

Source code in ckanext/tables/table.py
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
@dataclass(frozen=True)
class RowActionDefinition:
    """Defines an action that can be performed on a row.

    Attributes:
        action: Unique identifier for the action.
        label: Display label for the action.
        callback: Function to be called when the action is triggered.
        icon: (Optional) Icon class for the action.
        with_confirmation: (Optional) Whether to show a confirmation dialog before executing the action.
    """

    action: str
    label: str
    callback: Callable[[types.Row], types.ActionHandlerResult]
    icon: str | None = None
    with_confirmation: bool = False

    def __call__(self, row: types.Row) -> types.ActionHandlerResult:
        return self.callback(row)