Skip to content

useTableModals ​

Manages the three modal types used by a data table: the confirmation dialog, a custom content modal, and the show-data (detail view) modal.

File: vue/src/js/hooks/table/useTableModals.js


Props Factory ​

js
import { makeTableModalsProps } from '@/hooks/table/useTableModals'
PropTypeDefaultDescription
openCustomModalBooleanfalseInitialize with the custom modal open

Usage ​

js
import useTableModals, { makeTableModalsProps } from '@/hooks/table/useTableModals'

const {
  modals,
  customModalActive,
  actionDialogQuestion,
  openCustomModal,
  closeCustomModal,
  setModalType,
} = useTableModals(props, context)

Returns ​

State ​

NameTypeDescription
modalsRef<Object>Map of modal objects keyed by type: 'dialog', 'custom', 'show'
deleteModalActiveRef<Boolean>Legacy flag for the delete confirmation modal
customModalActiveRef<Boolean>Whether the custom content modal is visible
actionModalActiveRef<Boolean>Whether the action-result modal is visible
selectedActionRef<Object|null>The action that triggered the current modal
activeModalComputedRef<Object>The modal object for the current activeModalType

Computed ​

NameTypeDescription
actionDialogQuestionComputedRef<String>Translated confirmation question for the active action

Methods ​

NameSignatureDescription
openCustomModal() => voidOpen the custom modal
closeCustomModal() => voidClose the custom modal
setModalType(type: String) => voidSwitch the active modal type
bulkAction(action) => voidExecute a bulk action via datatableApi

Each entry in modals exposes a consistent interface:

js
modals.value.dialog.open()           // open the dialog
modals.value.dialog.close()          // close the dialog
modals.value.dialog.toggle(state?)   // toggle or set state

modals.value.dialog.set({ title: 'Delete?', description: '...' })  // set attributes
modals.value.dialog.setConfirmCallback(fn)   // set callback for Confirm button
modals.value.dialog.setRejectCallback(fn)    // set callback for Cancel button
modals.value.dialog.reset()                  // restore previous attribute values

The show modal additionally has:

js
modals.value.show.loadData(data)   // populate the detail view
modals.value.show.resetData()      // clear detail view data

Notes ​

  • The dialog modal is used for delete confirmations and action confirmations. Its confirmCallback / rejectCallback are set before opening.
  • The show modal displays arbitrary item data in a read-only panel.
  • The custom modal renders a slot-driven content area driven by store.state.datatable.customModal.

See Also ​