CRUD (Create, Read, Update, Delete)

By configuring api with add, edit, and delete methods and using formProps to define the form fields, you can quickly build a complete CRUD feature.

Basic Usage

Configure the form field types in the column formProps, and provide add, edit, del methods in api to enable CRUD.

  • Click the Add button to open the create form
  • Click the Edit action to open the edit form with the row data prefilled
  • Click the Delete action to open a confirmation dialog
  • If api.add/edit/del throws an error or returns false, the dialog will not close
浏览器不支持,请手动复制 crud.en.vue

onBefore Hook

operation.onBefore is triggered before the dialog opens, and can be used to:

  • Block the action: return false or throw an error, the dialog will not open
  • Replace data: return a new object, which will be used as the initial form data
  • Open normally: return void / undefined / true, default behavior
浏览器不支持,请手动复制 crud-on-before.en.vue

Types

formProps

TableColumn.formProps is used to configure how a column is displayed in the form. You can override the config for different action modes via addProps and editProps.

formProps?: Partial<FormColumn> & {
  addProps?: Partial<FormColumn>   // Extra config for the add mode, overrides formProps
  editProps?: Partial<FormColumn>  // Extra config for the edit mode, overrides formProps
}

operation.onBefore

onBefore?: (
  rowData: T,
  type: 'add' | 'edit' | 'del'
) => boolean | T | void | Promise<boolean | T | void>
ReturnDescription
falseBlock the action, the dialog will not open
Thrown errorBlock the action, the dialog will not open
Object TUse the returned object as the initial form data
void / undefined / trueOpen the dialog normally

api

MethodDescriptionType
addCreate API(rowData: T) => Promise<T | boolean | void>
editUpdate API(rowData: T) => Promise<T | boolean | void>
delDelete API(rowData: T) => Promise<T | boolean | void>

All three methods are optional. If they return false or throw an error, the dialog will not close; otherwise, the dialog closes and the table refreshes.