Are you an LLM? You can read better optimized documentation at /front/component/ma-pro-table/examples/custom-operations.md for this page in Markdown format
Custom Operations β
Demonstrates different types of action column configurations, including conditional display, custom styles, and complex operation logic.
Key Features β
- Multiple Action Types: Supports tiled, dropdown menu, auto-collapse display modes
- Conditional Display: Dynamically show/hide action buttons based on row data
- Context Menu: Supports row right-click menu functionality
- Drag Sorting: Supports row drag-and-drop reordering
- Batch Operations: Supports multi-selection and batch operation features
Action Column Configuration β
Basic Operation Configuration β
javascript
{
type: 'operation',
label: 'Actions',
width: 280,
fixed: 'right',
operationConfigure: {
type: 'auto', // auto/dropdown/tile
fold: 2, // Collapse threshold in auto mode
actions: [
{
name: 'view',
text: 'Details',
icon: 'view',
onClick: (data) => {
console.log('View details:', data.row)
}
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Operation Type Explanation β
1. Auto Mode (auto) β
javascript
operationConfigure: {
type: 'auto',
fold: 2, // Collapse after showing 2 buttons
actions: [...]
}
1
2
3
4
5
2
3
4
5
2. Dropdown Menu Mode (dropdown) β
javascript
operationConfigure: {
type: 'dropdown',
actions: [...]
}
1
2
3
4
2
3
4
3. Tiled Mode (tile) β
javascript
operationConfigure: {
type: 'tile',
actions: [...]
}
1
2
3
4
2
3
4
Action Button Configuration β
Basic Button β
javascript
{
name: 'edit',
text: 'Edit',
icon: 'edit',
onClick: (data, proxy) => {
console.log('Edit data:', data.row)
console.log('Table instance:', proxy)
}
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
Conditional Display β
javascript
{
name: 'approve',
text: 'Approve',
show: (data) => data.row.status === 'pending', // Conditional display
disabled: (data) => !data.row.canApprove, // Conditional disable
onClick: (data, proxy) => {
// Approval logic
proxy.refresh() // Refresh table
}
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Custom Styles β
javascript
{
name: 'delete',
text: 'Delete',
icon: 'delete',
linkProps: {
type: 'danger', // Button type
size: 'small' // Button size
},
onClick: (data) => {
ElMessageBox.confirm('Confirm deletion?', 'Confirmation', {
type: 'warning'
}).then(() => {
console.log('Delete:', data.row)
})
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Operation Ordering β
javascript
{
name: 'high-priority',
text: 'High Priority',
order: 1, // Sort weight, lower numbers come first
onClick: (data) => {
console.log('High priority operation')
}
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
Context Menu β
Enable Context Menu β
javascript
const options = {
rowContextMenu: {
enabled: true,
items: [
{
label: 'View Details',
icon: 'view',
onMenuClick: (data, event) => {
console.log('Right-click view:', data.row)
}
},
{
label: 'Copy Application',
icon: 'copy',
onMenuClick: (data, event) => {
console.log('Copy data:', data.row)
}
},
{
label: 'Delete',
icon: 'delete',
disabled: (data) => !data.row.canDelete, // Conditional disable
onMenuClick: (data, event) => {
console.log('Right-click delete:', data.row)
}
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Drag Sorting β
Enable Dragging β
javascript
const options = {
tableOptions: {
rowDrag: true // Enable row dragging
}
}
// Listen to drag events
const schema = {
tableColumns: [
{ type: 'sort', width: 60 }, // Drag column
// ...other columns
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
Drag Events β
vue
<MaProTable
:options="options"
:schema="schema"
@row-drag-sort="handleRowDragSort"
/>
<script setup>
const handleRowDragSort = (tableData) => {
console.log('New order:', tableData.map(item => item.title))
// Call API to save new order
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
Batch Operations β
Enable Multi-selection β
javascript
const options = {
tableOptions: {
selection: true // Enable multi-selection
}
}
1
2
3
4
5
2
3
4
5
Batch Operation Example β
vue
<template>
<div class="control-panel">
<el-button @click="batchApprove" type="primary">Batch Approve</el-button>
<el-button @click="batchDelete" type="danger">Batch Delete</el-button>
</div>
<MaProTable ref="tableRef" :options="options" :schema="schema" />
</template>
<script setup>
const tableRef = ref()
const batchApprove = () => {
const selectedRows = tableRef.value?.getTableRef?.()?.getSelectionRows?.()
console.log('Selected rows:', selectedRows)
}
const batchDelete = () => {
ElMessageBox.confirm('Confirm batch deletion?', 'Batch Operation', {
type: 'warning'
}).then(() => {
// Batch delete logic
tableRef.value?.refresh()
})
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Advanced Operation Examples β
Asynchronous Operation β
javascript
{
name: 'async-action',
text: 'Async Operation',
onClick: async (data, proxy) => {
try {
ElMessage.info('Processing...')
await someAsyncOperation(data.row.id)
ElMessage.success('Operation successful')
await proxy.refresh() // Refresh table
} catch (error) {
ElMessage.error('Operation failed')
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
Dialog Operation β
javascript
{
name: 'dialog-action',
text: 'Dialog Operation',
onClick: (data, proxy) => {
ElMessageBox.prompt('Please enter remarks', 'Operation Confirmation', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel'
}).then(({ value }) => {
console.log('Remarks:', value)
console.log('Data:', data.row)
proxy.refresh()
})
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
Custom operation functionality allows you to build complex interaction logic to meet various business scenario requirements.