列表上很多時候需要添加操作按鈕,
## 1. 第一種,表格右上角按鈕
這里可以用到 ui/table/*.php中的ops
格式如下:
```
class DemoTable extends TableInterface
{
public function ops()
{
return [
'edit' => [
'type' => 'link',
'label' => '編輯',
'icon' => 'el - icon - edit',
'url' => '/thinkadmin/user/edit',
'vars' => ['id'],
],
'del' => [
'type' => 'ajax',
'label' => '刪除',
'icon' => 'el - icon - delete',
'url' => '/thinkadmin/user/delete',
'vars' => ['id'],
'confirm' => '是否刪除管理員?',
]
];
}
}
```
配置項目
- type 操作類型,link是打開新窗口,ajax是調用一個ajax操作
- label 標題
- icon 操作圖標
- url 連接地址
- vars 鏈接地址上需要的參數,會自動從行數據中獲取對應的值
## 2. 第二種,列表數據中的按鈕
很多時候列表中的數據是需要增加鏈接,這個時候處理是,在table文件中header相應字段type設置為link,格式如下
```
~~~
class NewsTable extends TableInterface
{
public function header()
{
return [
'has_child'=> ['label' => '子菜單', 'type' => 'link', 'linkConfig' =>
[
['key' => 'has_child', 'value' => true, 'showValue' => false, 'label' => '管理子分類', 'icon' => 'fa fa-level-down', 'url' => '/mall/admin/mallCate', 'vars' =>['id@parent_id']],
]
];
}
}
```
linkConfig 配置
- key 數據對應的字段
- value 過濾值,行數據的數據等于 value的值的時候才顯示
- showValue 是否顯示數據所包含的值
- label 鏈接名稱
- icon 鏈接圖標
- url,vars 鏈接的地址和參數