
表格構建組件中表格是基于`layui`數據表格接口進行表格構建。為了便于理解表格構建方法可以結合`layui`數據表格文檔!
## 獲取構建器實例
1. `ViewBuilder`中獲取
```php
$viewBuilder = $this->viewBuilder;
$tableInstance = $viewBuilder->table;
```
2. `instance()`自身方法
```php
$tableInstance = TableBuilder::instance();
```
3. `new`關鍵詞
```php
$tableInstance = new TableBuilder([
'id' => ''
]);
```
## 示例 1
~~~
/**
* 列表
* @return string
* @throws \Throwable
* @throws \builder\base\InvalidInstanceException
* @throws \builder\base\NotFoundParamsException
*/
public function actionIndex()
{
$viewBuilder = $this->viewBuilder;
$table = $viewBuilder->table;
$table->setId('_admin_list');
if ($this->isAjax) { // AJAX
$table->setQuery(function () {
$params = $this->filteredGet;
$query = Admin::find();
$query->filterWhere([
'like', 'username', isset($params['keyword']) ? $params['keyword'] : null,
]);
return $query;
})
->setOrderBy(['id' => SORT_DESC])
->setColumns([
'id',
'username',
'password_hash' => function($row) {
return $row['password_hash'];
},
'email',
'mobile',
'status',
'group',
'created_at',
'updated_at',
'ro_delete3' => function ($row) {
return $row['id'] % 2;
},
])
->setExtraData(function (Query $query) {
return [
'tol' => $query->count(),
'a' => 100000,
];
});
$render = $viewBuilder->render();
//return $table->data;
return $render;
} else { // HTML
$table->setTitle('管理員列表')
->registerPointcut(H5::alert('頭部切點內容'))
->setExtraDataTpl([
'tol' => '當前總數量',
'a' => '所在院校',
])
//->registerPointcut(H5::alert('測試一下', 'success'))
//->registerPointcut(H5::alert('測試一下'), TableBuilder::POS_END)
->setAjaxRoute('admin/index')
// ->setLineStyle([
// 'height' => '350px',
// ])
->setTableHead([
$this->tableHead->checkbox()->style([]),
$this->tableHead->field('password_hash')->title('密碼')->minWidth(300),
$this->tableHead->field('username')->title('賬號')->editText('admin/edit'),
$this->tableHead->field('email')->title('郵箱')->maxWidth(200),
$this->tableHead->field('mobile')->title('手機號'),
$this->tableHead->field('created_at')->title('添加時間'),
$this->tableHead->field('updated_at')->title('更新時間'),
$this->tableHead->toolbar()->title('操作項')->maxWidth(210),
])
->setRowOperation([
// 詳情
$this->rowOperation->modal()->title('詳情')->icon('bi bi-plus')->route('admin/detail'),
$this->rowOperation->page()->title('測試')->icon('bi bi-x')->route('admin/detail')->params(['id' => 1])->targetBlank(),
$this->rowOperation->ajax()->title('刪除')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除1')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除2')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除3')->id('ro_delete3')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
])
->setToolbarCustom([
// 表單
$this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border')->title('表單')->icon('bi bi-plus-lg f15')->route('__upload/index')->width(916)->height(655),
// 列表
$this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border-green')->title('列表')->icon('bi bi-plus-lg f15')->route('admin/detail')->closeBtn(),
// 選項卡
$this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border-blue')->title('選項卡')->icon('bi bi-pencil-square f13')->route('admin/edit')->closeBtn(),
// AJAX
$this->toolbarCustom->page()->btnClass('layui-btn-primary layui-border-orange')->title('AJAX')->icon('bi bi-lock')->targetBlank()->params(['id'])->route('admin/add'),
])
->setToolbarFilter([
'keyword' => $this->toolbarFilter->text()->label('關鍵詞')->placeholder('請輸入賬號/姓名')->defaultValue()->attribute(['test' => 1])->uiClass('w-330 mr-3'),
'create_at' => $this->toolbarFilter->datetime()->style(['width' => '800px'])->label('注冊時間')->placeholder('請選擇注冊時間'),
'create_at1' => $this->toolbarFilter->datetime()->label('注冊時間')->placeholder('請選擇注冊時間'),
'status' => $this->toolbarFilter->select()->label('用戶狀態')->uiClass(['layui-col-sm12'])->placeholder('請選擇用戶狀態')->options([
'分組1' => [
'normal' => '正常',
'deny' => '禁用',
],
'分組2' => [
'A' => '不可以',
'B' => '可以',
],
])->disabled(['deny'])->uiClass('w-330 mr-3'),
'link1' => $this->toolbarFilter->selectLink()->label('聯動1')->placeholder('請選擇')->route('admin/link')->initOptions([
'測試1' => [
'a' => 'A',
'b' => 'B'
],
'測試2' => [
'c' => 'C',
'd' => 'D'
],
])->disabled(['d'])->targetLink('link2')->start()->uiClass('w-330'),
'link2' => $this->toolbarFilter->selectLink()->label('')->placeholder('請選擇')->route('admin/link')->targetLink('link3')->through()->uiClass('w-330'),
'link3' => $this->toolbarFilter->selectLink()->label('')->placeholder('請選擇')->end()->uiClass('w-330'),
])
->setAutoRequest(true);
return $viewBuilder->render();
}
}
~~~
## 下拉聯動接口
~~~
public function actionLink()
{
//return $this->as403('登錄已失效!');
$q = [
['value' => 1, 'text' => '狗'],
['value' => 2, 'text' => '豬', 'disabled' => true],
['value' => 3, 'text' => '羊'],
];
$q2 = [
'中國人民' => [
['value' => 4, 'text' => '狗1'],
['value' => 5, 'text' => '豬1', 'disabled' => true],
['value' => 6, 'text' => '羊1'],
],
'世界什么' => [
['value' => 7, 'text' => '狗2'],
['value' => 8, 'text' => '豬2', 'disabled' => true],
['value' => 9, 'text' => '羊2'],
],
];
return $this->asOk('success', $q2);
}
~~~
## 示例 2
~~~
/**
* 表格測試
* @return string
* @throws \yii\base\InvalidConfigException
*/
public function actionTable()
{
$tableBuilder = TableBuilder::instance();
if ($this->isAjax) { // AJAX
return $tableBuilder->setQuery(function () {
return Admin::find();
})
->setOrderBy(['id' => SORT_DESC])
->setColumns([
'id',
'username',
'password_hash',
'email',
'mobile',
'status',
'group',
'created_at',
'updated_at',
'ro_delete3' => function ($row) {
return $row['id'] % 2;
},
])
->render();
} else { // HTML
// 表格1
return $tableBuilder->setTitle('管理員列表1')
//->setAutoRequest(false)
//->registerPointcut(H5::alert('測試一下', 'success'))
//->registerPointcut(H5::alert('測試一下'), TableBuilder::POS_END)
->setTableHead([
$this->tableHead->checkbox(),
$this->tableHead->field('id')->title('ID_1'),
$this->tableHead->field('username')->title('賬號_1')->editText('admin/edit'),
$this->tableHead->field('password_hash')->title('密碼_1'),
$this->tableHead->field('email')->title('郵箱_1'),
$this->tableHead->field('mobile')->title('手機號_1'),
$this->tableHead->field('status')->title('狀態_1'),
$this->tableHead->field('group')->title('分組_1'),
$this->tableHead->field('created_at')->title('添加時間_1'),
$this->tableHead->field('updated_at')->title('更新時間_1'),
$this->tableHead->toolbar()->title('操作項_1'),
])
->setRowOperation([
// 詳情
$this->rowOperation->modal()->title('詳情_1')->icon('bi bi-plus-lg f15')->route('admin/detail')->closeBtn(),
$this->rowOperation->ajax()->title('刪除_1')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除1_1')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除2_1')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除3_1')->id('ro_delete3')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
])
->setToolbarCustom([
// 表單
$this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border-red')->title('表單_1')->icon('bi bi-plus-lg f15')->route('admin/add')->params(['_bid' => $tableBuilder->id]),
// 列表
$this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border-black')->title('列表_1')->icon('bi bi-plus-lg f15')->route('admin/detail')->closeBtn(),
// 選項卡
$this->toolbarCustom->modal()->btnClass('layui-btn layui-btn-disabled')->title('選項卡_1')->icon('bi bi-pencil-square f13')->route('admin/edit')->closeBtn(),
// AJAX
$this->toolbarCustom->page()->title('AJAX_1')->icon('bi bi-lock')->targetBlank()->params(['id'])->route('admin/add'),
])
->setToolbarFilter([
'keyword' => $this->toolbarFilter->text()->label('關鍵詞')->placeholder('請輸入賬號/姓名')->defaultValue()->attribute(['test' => 1]),
//'username' => $this->toolbarFilter->datetime()->style(['width' => '800px'])->label('注冊時間')->placeholder('請選擇注冊時間'),
//'username' => $this->toolbarFilter->datetime()->label('注冊時間_1')->placeholder('請選擇注冊時間'),
//'status' => $this->toolbarFilter->select()->label('用戶狀態_1')->placeholder('請選擇用戶狀態')->options(['normal' => '正常', 'deny' => '禁用',]),
//'link1' => $this->toolbarFilter->selectLink()->label('聯動1_1')->placeholder('請選擇')->route('admin/link')->initOptions(['a' => 'A', 'b' => 'B'])->targetLink('link2')->start(),
//'link2' => $this->toolbarFilter->selectLink()->label('聯動2_1')->placeholder('請選擇')->route('admin/link')->targetLink('link3')->through(),
//'link3' => $this->toolbarFilter->selectLink()->label('聯動3_1')->placeholder('請選擇')->route('admin/link')->targetLink('link4')->through(),
//'link4' => $this->toolbarFilter->selectLink()->label('聯動2_1')->placeholder('請選擇')->end(),
])->render();
}
}
~~~
## 完整示例
~~~
<?php
/**
* @link https://ym2.cleverstone.top
* @copyright Copyright (c) 2020 Yii Manager Software LLC
*/
namespace backend\controllers;
use builder\base\BaseController;
use builder\form\FormBuilder;
use builder\helper\D;
use builder\helper\H5;
use builder\table\TableBuilder;
use builder\widget\ajax\MediaList;
use common\models\Admin;
use yii\db\Query;
use yii\helpers\Json;
/**
* 管理員
* @author cleverstone
* @since ym2.0
*/
class AdminController extends BaseController
{
public $actionVerbs = [
'index' => ['GET'],
'link' => ['GET'],
'edit' => ['GET', 'POST'],
'delete' => ['POST'],
'add' => ['GET', 'POST'],
'detail' => ['GET'],
];
public $guestActions = [
'index',
'edit',
'delete',
'add',
'link',
'detail',
];
/**
* 列表
* @return string
* @throws \Throwable
* @throws \builder\base\InvalidInstanceException
* @throws \builder\base\NotFoundParamsException
*/
public function actionIndex()
{
$viewBuilder = $this->viewBuilder;
$table = $viewBuilder->table;
$table->setId('_admin_list');
if ($this->isAjax) { // AJAX
$table->setQuery(function () {
$params = $this->filteredGet;
$query = Admin::find();
$query->filterWhere([
'like', 'username', isset($params['keyword']) ? $params['keyword'] : null,
]);
return $query;
})
->setOrderBy(['id' => SORT_DESC])
->setColumns([
'id',
'username',
'password_hash' => function($row) {
return $row['password_hash'];
},
'email',
'mobile',
'status',
'group',
'created_at',
'updated_at',
'ro_delete3' => function ($row) {
return $row['id'] % 2;
},
])
->setExtraData(function (Query $query) {
return [
'tol' => $query->count(),
'a' => 100000,
];
});
$render = $viewBuilder->render();
//return $table->data;
return $render;
} else { // HTML
$table->setTitle('管理員列表')
->registerPointcut(H5::alert('頭部切點內容'))
->setExtraDataTpl([
'tol' => '當前總數量',
'a' => '所在院校',
])
//->registerPointcut(H5::alert('測試一下', 'success'))
//->registerPointcut(H5::alert('測試一下'), TableBuilder::POS_END)
->setAjaxRoute('admin/index')
// ->setLineStyle([
// 'height' => '350px',
// ])
->setTableHead([
$this->tableHead->checkbox()->style([]),
$this->tableHead->field('password_hash')->title('密碼')->minWidth(300),
$this->tableHead->field('username')->title('賬號')->editText('admin/edit'),
$this->tableHead->field('email')->title('郵箱')->maxWidth(200),
$this->tableHead->field('mobile')->title('手機號'),
$this->tableHead->field('created_at')->title('添加時間'),
$this->tableHead->field('updated_at')->title('更新時間'),
$this->tableHead->toolbar()->title('操作項')->maxWidth(210),
])
->setRowOperation([
// 詳情
$this->rowOperation->modal()->title('詳情')->icon('bi bi-plus')->route('admin/detail'),
$this->rowOperation->page()->title('測試')->icon('bi bi-x')->route('admin/detail')->params(['id' => 1])->targetBlank(),
$this->rowOperation->ajax()->title('刪除')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除1')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除2')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除3')->id('ro_delete3')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
])
->setToolbarCustom([
// 表單
$this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border')->title('表單')->icon('bi bi-plus-lg f15')->route('__upload/index')->width(916)->height(655),
// 列表
$this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border-green')->title('列表')->icon('bi bi-plus-lg f15')->route('admin/detail')->closeBtn(),
// 選項卡
$this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border-blue')->title('選項卡')->icon('bi bi-pencil-square f13')->route('admin/edit')->closeBtn(),
// AJAX
$this->toolbarCustom->page()->btnClass('layui-btn-primary layui-border-orange')->title('AJAX')->icon('bi bi-lock')->targetBlank()->params(['id'])->route('admin/add'),
])
->setToolbarFilter([
'keyword' => $this->toolbarFilter->text()->label('關鍵詞')->placeholder('請輸入賬號/姓名')->defaultValue()->attribute(['test' => 1])->uiClass('w-330 mr-3'),
'create_at' => $this->toolbarFilter->datetime()->style(['width' => '800px'])->label('注冊時間')->placeholder('請選擇注冊時間'),
'create_at1' => $this->toolbarFilter->datetime()->label('注冊時間')->placeholder('請選擇注冊時間'),
'status' => $this->toolbarFilter->select()->label('用戶狀態')->uiClass(['layui-col-sm12'])->placeholder('請選擇用戶狀態')->options([
'分組1' => [
'normal' => '正常',
'deny' => '禁用',
],
'分組2' => [
'A' => '不可以',
'B' => '可以',
],
])->disabled(['deny'])->uiClass('w-330 mr-3'),
'link1' => $this->toolbarFilter->selectLink()->label('聯動1')->placeholder('請選擇')->route('admin/link')->initOptions([
'測試1' => [
'a' => 'A',
'b' => 'B'
],
'測試2' => [
'c' => 'C',
'd' => 'D'
],
])->disabled(['d'])->targetLink('link2')->start()->uiClass('w-330'),
'link2' => $this->toolbarFilter->selectLink()->label('')->placeholder('請選擇')->route('admin/link')->targetLink('link3')->through()->uiClass('w-330'),
'link3' => $this->toolbarFilter->selectLink()->label('')->placeholder('請選擇')->end()->uiClass('w-330'),
])
->setAutoRequest(true);
return $viewBuilder->render();
}
}
public function actionLink()
{
//return $this->as403('登錄已失效!');
$q = [
['value' => 1, 'text' => '狗'],
['value' => 2, 'text' => '豬', 'disabled' => true],
['value' => 3, 'text' => '羊'],
];
$q2 = [
'中國人民' => [
['value' => 4, 'text' => '狗1'],
['value' => 5, 'text' => '豬1', 'disabled' => true],
['value' => 6, 'text' => '羊1'],
],
'世界什么' => [
['value' => 7, 'text' => '狗2'],
['value' => 8, 'text' => '豬2', 'disabled' => true],
['value' => 9, 'text' => '羊2'],
],
];
return $this->asOk('success', $q2);
}
/**
* @return string
* @throws \Throwable
* @throws \builder\base\InvalidInstanceException
* @throws \builder\base\NotFoundParamsException
*/
public function actionAdd()
{
if ($this->isPost) {
// return $this->as403('登錄已失效!');
return $this->asOk('刪除成功!');
// return $this->asFail('刪除失敗, 參數錯誤!');
} else {
$get = $this->filteredGet;
$viewBuilder = $this->viewBuilder;
$viewBuilder->setPartial();
$form = $viewBuilder->form;
$form->registerPointcut(H5::alert('我是表單切點', 'info', ['class' => ['mb-0']]))
->setFormControl([
'j' => $this->formControl->textarea()->label('文本域')->required()->defaultValue('臥槽我\r\n臥槽"\'' . PHP_EOL),
'k' => $this->formControl->checkbox()->defaultValue(['a'])->options(['a' => '我', 'b' => '是', 'c' => '神',])->required()->label('標簽')->tag(),
'l' => $this->formControl->checkbox()->defaultValue(['e', 'f'])->options(['d' => '我', 'e' => '是', 'f' => '神',])->required()->label('多選'),
'm' => $this->formControl->sw()->label('開關')->required()->checked(),
'n' => $this->formControl->hidden()->defaultValue('沖沖沖'),
'o' => $this->formControl->password()->label('密碼')->required()->defaultValue('123456'),
'p' => $this->formControl->radio()->options(['g' => '我', 'h' => '是', 'i' => '神',])->defaultValue('h')->required()->label('單選'),
'q' => $this->formControl->range()->required()->label('范圍')->defaultValue(1),
])
->setCloseBtn()
->setSubmitBtn()
->setSubmittedCalls([
'parent' => isset($get['_bid']) ? $get['_bid'] : null,
])
->setAutoClose(true);
return $viewBuilder->render();
}
}
/**
* @return string
* @throws \builder\base\InvalidInstanceException
* @throws \builder\base\NotFoundParamsException
*/
public function actionDetail()
{
$viewBuilder = $this->viewBuilder;
$viewBuilder->setPartial();
$lists = $viewBuilder->lists;
$lists->setTitle('詳情構建器')
->setListRows([
[
'班級' => $this->listRows->item('二班')->thAttribute(['width' => 90]),
'班主任' => $this->listRows->item('李陽')->thAttribute(['width' => 90]),
'聯系方式' => $this->listRows->item('12225478878')->thAttribute(['width' => 90]),
],
[
'用戶名' => $this->listRows->item('楊慧磊'),
'積分' => $this->listRows->item(500),
'狀態' => $this->listRows->item(H5::badge('成功')),
],
'手機號' => $this->listRows->item(function () {
return '15030321254';
})->tdAttribute(['colspan' => 5]),
'訂單號' => $this->listRows->item('N01878016587493544427')->tdAttribute(['colspan' => 5]),
'平臺' => $this->listRows->item('淘寶')->tdAttribute(['colspan' => 5]),
'店鋪' => $this->listRows->item('Wd028,愛吃魚')->tdAttribute(['colspan' => 5]),
'省' => $this->listRows->item('河南省')->tdAttribute(['colspan' => 5]),
'市' => $this->listRows->item('鄭州市')->tdAttribute(['colspan' => 5]),
'區(縣)' => $this->listRows->item('金水區')->tdAttribute(['colspan' => 5]),
'詳細地址' => $this->listRows->item('國貿大廈102')->tdAttribute(['colspan' => 5]),
'商品信息' => $this->listRows->item('閃迪512g/1700 CFE卡')->tdAttribute(['colspan' => 5]),
'員工' => $this->listRows->item('李四')->tdAttribute(['colspan' => 5]),
'訂單金額' => $this->listRows->item('100.00')->tdAttribute(['colspan' => 5]),
'收益' => $this->listRows->item('20.00')->tdAttribute(['colspan' => 5]),
'提成' => $this->listRows->item('5.00')->tdAttribute(['colspan' => 5]),
'注冊時間' => $this->listRows->item('2023/03/02 02:00')->tdAttribute(['colspan' => 5]),
]);
return $viewBuilder->render();
}
/**
* 表格測試
* @return string
* @throws \yii\base\InvalidConfigException
*/
public function actionTable()
{
$tableBuilder = TableBuilder::instance();
if ($this->isAjax) { // AJAX
return $tableBuilder->setQuery(function () {
return Admin::find();
})
->setOrderBy(['id' => SORT_DESC])
->setColumns([
'id',
'username',
'password_hash',
'email',
'mobile',
'status',
'group',
'created_at',
'updated_at',
'ro_delete3' => function ($row) {
return $row['id'] % 2;
},
])
->render();
} else { // HTML
// 表格1
return $tableBuilder->setTitle('管理員列表1')
//->setAutoRequest(false)
//->registerPointcut(H5::alert('測試一下', 'success'))
//->registerPointcut(H5::alert('測試一下'), TableBuilder::POS_END)
->setTableHead([
$this->tableHead->checkbox(),
$this->tableHead->field('id')->title('ID_1'),
$this->tableHead->field('username')->title('賬號_1')->editText('admin/edit'),
$this->tableHead->field('password_hash')->title('密碼_1'),
$this->tableHead->field('email')->title('郵箱_1'),
$this->tableHead->field('mobile')->title('手機號_1'),
$this->tableHead->field('status')->title('狀態_1'),
$this->tableHead->field('group')->title('分組_1'),
$this->tableHead->field('created_at')->title('添加時間_1'),
$this->tableHead->field('updated_at')->title('更新時間_1'),
$this->tableHead->toolbar()->title('操作項_1'),
])
->setRowOperation([
// 詳情
$this->rowOperation->modal()->title('詳情_1')->icon('bi bi-plus-lg f15')->route('admin/detail')->closeBtn(),
$this->rowOperation->ajax()->title('刪除_1')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除1_1')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除2_1')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除3_1')->id('ro_delete3')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
])
->setToolbarCustom([
// 表單
$this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border-red')->title('表單_1')->icon('bi bi-plus-lg f15')->route('admin/add')->params(['_bid' => $tableBuilder->id]),
// 列表
$this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border-black')->title('列表_1')->icon('bi bi-plus-lg f15')->route('admin/detail')->closeBtn(),
// 選項卡
$this->toolbarCustom->modal()->btnClass('layui-btn layui-btn-disabled')->title('選項卡_1')->icon('bi bi-pencil-square f13')->route('admin/edit')->closeBtn(),
// AJAX
$this->toolbarCustom->page()->title('AJAX_1')->icon('bi bi-lock')->targetBlank()->params(['id'])->route('admin/add'),
])
->setToolbarFilter([
'keyword' => $this->toolbarFilter->text()->label('關鍵詞')->placeholder('請輸入賬號/姓名')->defaultValue()->attribute(['test' => 1]),
//'username' => $this->toolbarFilter->datetime()->style(['width' => '800px'])->label('注冊時間')->placeholder('請選擇注冊時間'),
//'username' => $this->toolbarFilter->datetime()->label('注冊時間_1')->placeholder('請選擇注冊時間'),
//'status' => $this->toolbarFilter->select()->label('用戶狀態_1')->placeholder('請選擇用戶狀態')->options(['normal' => '正常', 'deny' => '禁用',]),
//'link1' => $this->toolbarFilter->selectLink()->label('聯動1_1')->placeholder('請選擇')->route('admin/link')->initOptions(['a' => 'A', 'b' => 'B'])->targetLink('link2')->start(),
//'link2' => $this->toolbarFilter->selectLink()->label('聯動2_1')->placeholder('請選擇')->route('admin/link')->targetLink('link3')->through(),
//'link3' => $this->toolbarFilter->selectLink()->label('聯動3_1')->placeholder('請選擇')->route('admin/link')->targetLink('link4')->through(),
//'link4' => $this->toolbarFilter->selectLink()->label('聯動2_1')->placeholder('請選擇')->end(),
])->render();
}
}
/**
* tab選項卡構建
* @return string
* @throws \builder\base\InvalidInstanceException
* @throws \builder\base\NotFoundParamsException
* @throws \yii\base\InvalidConfigException
*/
public function actionEdit()
{
// 選項卡 - 表格1
$table1 = TableBuilder::instance([
'id' => 'table1_1',
]);
// 選項卡 - 表格2
$table2 = TableBuilder::instance([
'id' => 'table2_1',
]);
if ($this->isAjax) { // AJAX
switch ($table1->builderId) {
case $table1->id: // 表格1
return $table1->setQuery(function () {
return Admin::find();
})
->setOrderBy(['id' => SORT_DESC])
->setColumns([
'id',
'username',
'password_hash',
'email',
'mobile',
'status',
'group',
'created_at',
'updated_at',
'ro_delete3' => function ($row) {
return $row['id'] % 2;
},
])->render();
case $table2->id: // 表格2
return $table2->setQuery(function () {
return Admin::find();
})
->setOrderBy(['id' => SORT_DESC])
->setColumns([
'id',
'username',
'password_hash',
'email',
'mobile',
'status',
'group',
'created_at',
'updated_at',
'ro_delete3' => function ($row) {
return $row['id'] % 2;
},
])->render();
}
} else { // HTML
// 表格1
$table1->setTitle('管理員列表1')
->setAutoRequest(false)
//->registerPointcut(H5::alert('測試一下', 'success'))
//->registerPointcut(H5::alert('測試一下'), TableBuilder::POS_END)
->setTableHead([
$this->tableHead->checkbox(),
$this->tableHead->field('id')->title('ID_1'),
$this->tableHead->field('username')->title('賬號_1')->editText('admin/edit'),
$this->tableHead->field('password_hash')->title('密碼_1'),
$this->tableHead->field('email')->title('郵箱_1'),
$this->tableHead->field('mobile')->title('手機號_1'),
$this->tableHead->field('status')->title('狀態_1'),
$this->tableHead->field('group')->title('分組_1'),
$this->tableHead->field('created_at')->title('添加時間_1'),
$this->tableHead->field('updated_at')->title('更新時間_1'),
$this->tableHead->toolbar()->title('操作項_1'),
])
->setRowOperation([
// 詳情
$this->rowOperation->modal()->title('詳情_1')->icon('bi bi-plus-lg f15')->route('admin/detail')->closeBtn(),
$this->rowOperation->ajax()->title('刪除_1')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除1_1')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除2_1')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除3_1')->id('ro_delete3')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
])
->setToolbarCustom([
// 表單
$this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border-red')->title('表單_1')->icon('bi bi-plus-lg f15')->route('admin/add')->params(['_bid' => $table1->id]),
// 列表
$this->toolbarCustom->modal()->btnClass('layui-btn-primary layui-border-black')->title('列表_1')->icon('bi bi-plus-lg f15')->route('admin/detail')->closeBtn(),
// 選項卡
$this->toolbarCustom->modal()->btnClass('layui-btn layui-btn-disabled')->title('選項卡_1')->icon('bi bi-pencil-square f13')->route('admin/edit')->closeBtn(),
// AJAX
$this->toolbarCustom->page()->title('AJAX_1')->icon('bi bi-lock')->targetBlank()->params(['id'])->route('admin/add'),
])
->setToolbarFilter([
'keyword' => $this->toolbarFilter->text()->label('關鍵詞')->placeholder('請輸入賬號/姓名')->defaultValue()->attribute(['test' => 1]),
//'username' => $this->toolbarFilter->datetime()->style(['width' => '800px'])->label('注冊時間')->placeholder('請選擇注冊時間'),
//'username' => $this->toolbarFilter->datetime()->label('注冊時間_1')->placeholder('請選擇注冊時間'),
//'status' => $this->toolbarFilter->select()->label('用戶狀態_1')->placeholder('請選擇用戶狀態')->options(['normal' => '正常', 'deny' => '禁用',]),
//'link1' => $this->toolbarFilter->selectLink()->label('聯動1_1')->placeholder('請選擇')->route('admin/link')->initOptions(['a' => 'A', 'b' => 'B'])->targetLink('link2')->start(),
//'link2' => $this->toolbarFilter->selectLink()->label('聯動2_1')->placeholder('請選擇')->route('admin/link')->targetLink('link3')->through(),
//'link3' => $this->toolbarFilter->selectLink()->label('聯動3_1')->placeholder('請選擇')->route('admin/link')->targetLink('link4')->through(),
//'link4' => $this->toolbarFilter->selectLink()->label('聯動2_1')->placeholder('請選擇')->end(),
]);
// 表格2
$table2->setTitle('管理員列表2')
->setAutoRequest(false)
//->registerPointcut(H5::alert('測試一下', 'success'))
//->registerPointcut(H5::alert('測試一下'), TableBuilder::POS_END)
->setTableHead([
$this->tableHead->checkbox(),
$this->tableHead->field('id')->title('ID_2'),
$this->tableHead->field('username')->title('賬號_2')->editText('admin/edit'),
$this->tableHead->field('password_hash')->title('密碼_2'),
$this->tableHead->field('email')->title('郵箱_2'),
$this->tableHead->field('mobile')->title('手機號_2'),
$this->tableHead->field('status')->title('狀態_2'),
$this->tableHead->field('group')->title('分組_2'),
$this->tableHead->field('created_at')->title('添加時間_2'),
$this->tableHead->field('updated_at')->title('更新時間_2'),
$this->tableHead->toolbar()->title('操作項_2'),
])
->setRowOperation([
// 詳情
$this->rowOperation->modal()->title('詳情_2')->icon('bi bi-plus-lg f15')->route('admin/detail')->closeBtn(),
$this->rowOperation->ajax()->title('刪除_2')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除1_2')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除2_2')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
$this->rowOperation->ajax()->title('我要刪除3_2')->id('ro_delete3')->icon('bi bi-x-lg')->route('admin/delete')->method('POST')->group(),
])
->setToolbarCustom([
// 表單
$this->toolbarCustom->modal()->btnClass('layui-btn-primary')->title('表單_2')->icon('bi bi-plus-lg f15')->route('admin/add')->params(['_bid' => $table2->id]),
// 列表
$this->toolbarCustom->modal()->btnClass('layui-btn-warm')->title('列表_2')->icon('bi bi-plus-lg f15')->route('admin/detail')->closeBtn(),
// 選項卡
$this->toolbarCustom->modal()->btnClass('layui-btn-danger')->title('選項卡_2')->icon('bi bi-pencil-square f13')->route('admin/edit')->closeBtn(),
// AJAX
$this->toolbarCustom->page()->btnClass('layui-btn-normal')->title('AJAX_2')->icon('bi bi-lock')->targetBlank()->params(['id'])->route('admin/add'),
])
->setToolbarFilter([
'keyword' => $this->toolbarFilter->text()->label('關鍵詞')->placeholder('請輸入賬號/姓名')->defaultValue()->attribute(['test' => 1]),
//'username' => $this->toolbarFilter->datetime()->style(['width' => '800px'])->label('注冊時間')->placeholder('請選擇注冊時間'),
//'username' => $this->toolbarFilter->datetime()->label('注冊時間_2')->placeholder('請選擇注冊時間'),
//'status' => $this->toolbarFilter->select()->label('用戶狀態_2')->placeholder('請選擇用戶狀態')->options(['normal' => '正常', 'deny' => '禁用',]),
//'link1' => $this->toolbarFilter->selectLink()->label('聯動1_2')->placeholder('請選擇')->route('admin/link')->initOptions(['a' => 'A', 'b' => 'B'])->targetLink('link2')->start(),
//'link2' => $this->toolbarFilter->selectLink()->label('聯動2_2')->placeholder('請選擇')->route('admin/link')->targetLink('link3')->through(),
//'link3' => $this->toolbarFilter->selectLink()->label('聯動3_2')->placeholder('請選擇')->route('admin/link')->targetLink('link4')->through(),
//'link4' => $this->toolbarFilter->selectLink()->label('聯動2_2')->placeholder('請選擇')->end(),
]);
}
// 視圖構建器開始
$viewBuilder = $this->viewBuilder;
$viewBuilder->setPartial();
// 選項卡
$tab = $viewBuilder->tab;
$tab
->setTheme()
->setTitle('選項卡')
->setTabItem([
'自定義' => $this->tabItem->custom('自定義的內容'),
'表格1' => $this->tabItem->builder($table1)->switchProperty(),
'表格2' => $this->tabItem->builder($table2)->switchProperty()->selected(),
]);
return $viewBuilder->render();
}
public function actionDelete()
{
return $this->as403('登錄已失效!');
// return $this->asOk('刪除成功!');
// return $this->asFail('刪除失敗, 參數錯誤!');
}
}
~~~
- 簡介
- 安裝和配置
- 常用CLI命令
- 接口文檔生成工具
- 代碼提交
- 視圖構建器
- 表格 Table
- HTML
- 繼承布局 partial
- 表格標題 title
- ajax路由 ajaxRoute
- 表格根布局 rootLayout
- 表格主容器 classname
- 表格寬度 width
- 表格高度 height
- 表格最大高度 maxHeight
- 普通單元格的最小寬度 cellMinWidth
- 普通單元格的最大寬度 cellMaxWidth
- 開啟表格多行樣式 lineStyle
- 表格主鍵 primaryKey
- 設置額外的靜態資源包 extraAssetBundle
- 設置額外的CSS extraCss
- 設置額外的JS extraJs
- 分頁 page
- limits 頁碼選項
- limit 默認數據條數
- 工具篩選 toolbarFilter
- 工具篩選助手 toolbarFilter
- text文本
- select下拉框
- selectLink下拉聯動
- number 數字
- datetime/date/year/month/time 日期
- 表格行頭 tableHead
- 行頭助手 tableHead
- checkbox 多選列
- field 普通列
- toolbar 工具列
- 自定義工具欄 toolbarCustom
- 自定義工具欄助手 toolbarCustom
- 工具欄 - modal模態框
- 工具欄 - page單頁
- 工具欄 - ajax異步
- 表格行操作 rowOperation
- 行操作助手 rowOperation
- modal模態框
- page單頁
- AJAX調用
- 列篩選工具項 columnFilter
- 打印工具項 toolbarPrint
- 導出工具項 toolbarExports
- 窗口刷新工具項 toolbarRefresh
- (前端)是否開啟行合計 openTotalRow
- 初始請求 autoRequest
- 數據統計(額外的數據模板) HTML
- 設置表格切點內容 registerPointcut
- AJAX異步
- 設置表格數據或Query實例 query
- 數據統計(額外的數據模板) extraData
- Query排序 orderBy
- 表格數據列 columns
- 列依賴 columnDependency
- (后端)是否開啟行合計 totalRow
- 分頁 page
- 樹表格 TreeTable
- HTML~
- 繼承布局 partial
- 樹表格標題 title
- ajax路由 ajaxRoute
- children路由 treeAsyncOption
- 自定義屬性名選項 treeCustomNameOption
- 視圖相關的屬性集合 treeViewOption
- 數據相關屬性集合 treeDataOption
- 樹形表格根布局 rootLayout
- 樹表格主容器 classname
- 樹形表格寬度 width
- 樹形表格高度 height
- 樹形表格最大高度 maxHeight
- 普通單元格的最小寬度 cellMinWidth
- 普通單元格的最大寬度 cellMaxWidth
- 開啟多行樣式 lineStyle
- 設置主鍵 primaryKey
- 分頁 page
- limits 頁碼選項~
- limit 默認數據條數~
- 工具篩選 ttToolbarFilter
- 工具篩選助手 ttToolbarFilter
- text文本~
- select下拉框~
- selectLink下拉聯動
- number 數字~
- datetime/date/year/month/time 日期~
- 樹表格行頭 treeTableHead
- 行頭助手 treeTableHead
- checkbox 多選列
- field 普通列
- toolbar 工具列
- 頭部自定義工具欄 ttToolbarCustom
- 自定義工具欄助手 ttToolbarCustom
- 工具欄 - modal模態框~
- 工具欄 - page單頁~
- 工具欄 - ajax異步~
- 樹形表格行操作 ttRowOperation
- 行操作助手 ttRowOperation
- modal模態框
- page單頁~
- AJAX調用
- 列篩選工具項 ttColumnFilter
- 打印工具項 ttToolbarPrint
- 導出工具項 ttToolbarExports
- 窗口刷新工具項 ttToolbarRefresh
- (前端)是否開啟行合計 openTotalRow
- 初始請求 autoRequest~
- 數據統計(額外的數據模板) HTML
- 設置表格切點內容 registerPointcut
- 設置額外的靜態資源包 extraAssetBundle
- 設置額外的CSS extraCss~
- 設置額外的JS extraJs~
- AJAX
- 設置數據或Query實例 query
- 數據統計(額外的數據模板) extraData
- Query排序 orderBy
- 樹形表格數據列 ttColumns
- 列依賴 ttColumnDependency
- 自定義行合計(后端) totalRow
- 分頁 page~
- 表單 Form
- 表單布局 partial
- 提交鏈接 submitUrl
- 表單標題 title
- 表單根布局 rootLayout
- 表單尾部布局 footerLayout
- 表單分組 group
- 組柵欄格 groupCol
- 組布局 groupLayout
- 組注釋 groupComment
- 必填標記 requiredStyle
- 設置提交按鈕 submitBtn
- 設置重置按鈕 resetBtn
- 設置彈窗關閉按鈕 closeBtn
- 設置表單返回按鈕 backBtn
- 設置額外的按鈕 extraBtn
- 提交后自動關閉 autoClose
- 提交后自動返回 autoBack
- 提交確認 submitConfirm
- 提交后回調 submittedCalls
- 提交后重定向 submittedRedirect
- 設置額外的CSS extraCss
- 設置額外的JS extraJs
- 設置額外的資源包 extraAssetBundle
- 表單控件項 formControl
- 表單控件助手 formControl
- 文本 text
- 文本域 textarea
- 數字 number
- 密碼 password
- 隱藏控件 hidden
- 靜態文本 staticText
- 日期 datetime/date/year/month/time
- 滑塊 range
- 富文本 richText
- 單選 radio
- 多選(標簽)控件 checkbox / tag
- 開關 sw
- 文件 file
- (select2)下拉選擇 Select
- (select2)下拉聯動 SelectLink
- (select2)動態下拉 selectDynamic
- 區間 section
- 動態標簽 tag
- 交互 - 觸發器 trigger
- 交互 - 值連接 valueLink
- 交互 - 動態控件dynamicControl
- 控件項助手dynamicControl
- 文本 text~
- 文本域 textarea~
- 多選 checkbox~
- 開關 sw~
- 日期 datetime/date/year/month/time~
- 數字 number~
- 密碼 password ~
- 單選 radio ~
- 滑塊 range~
- 文件 file~
- 區間 section~
- (select2)下拉選擇 select~
- 下拉擴展 xselect
- 下拉樹 xselectTree
- 自定義(遠程)下拉 xselectRemote
- 下拉級聯 xselectCascader
- 注冊HTML切點+
- 分步表單 FormStep
- 局部繼承 partial
- 提交路由 submitUrl
- 標題 title
- 根布局 rootLayout
- 分步項 stepItem
- 提交按鈕 submitBtn
- 彈窗關閉按鈕 closeBtn
- 頁面返回按鈕 backBtn
- 設置額外的按鈕 extraBtn~
- 設置自動關閉 autoClose
- 設置自動返回 autoBack
- 設置提交確認框 submitConfirm
- 提交后回調 submittedCalls~
- 提交后重定向 fssRedirect
- 設置額外的CSS extraCss~~
- 設置額外的JS extraJs~~
- 設置額外的資源包 extraAssetBundle~
- 注冊HTML切點~
- 選項卡 Tab
- 選項卡局部繼承 partial
- 選項卡標題 title
- 選項卡根布局 rootLayout
- 選項卡風格 theme
- 選項卡內容項 tabItem
- 內容注冊助手 tabItem
- 注入構建器實例 builder
- 注入自定內容
- 設置額外的CSS extraCss~~~~
- 設置額外的JS extraJs~~~~
- 設置額外的資源包 extraAssetBundle~~~
- 注冊HTML切點
- 詳情列表 Lists
- 局部布局 partial
- 列表標題 title
- 根布局 rootLayout~
- 列表布局 listLayout
- 設置行數據 listRows
- 行數據助手 listRows
- 設置行
- 設置額外的CSS extraCss~~~
- 設置額外的JS extraJs~~~
- 設置額外的資源包 extraAssetBundle~~
- 注冊內容切點~
- 樹組件 Tree
- HTML方法
- 獨立繼承 partial
- AJAX路由 ajaxRoute
- 樹組件標題 title
- 樹組件根布局 rootLayout
- 樹布局 treeLayout
- 復選框 showCheckbox
- 手風琴模式 accordion
- 僅左側圖標伸縮 onlyIconControl
- 是否新窗口跳轉 isJump
- 是否開啟節點連接線 showLine
- 是否顯示全選/反選按鈕 switchCheckedBtn
- 是否顯示展開/折疊按鈕 switchSpreadBtn
- 是否初始化數據請求 autoRequest
- 額外的CSS extraCss
- 額外的JS extraJs
- 額外的資源包 extraAssetBundle
- 注冊內容切點
- 自定義操作項 operationItem
- 助手 operationItem
- 模態框 modal
- 單頁 page
- 異步 ajax
- AJAX.異步
- 設置數據 data
- 助手類
- 應用助手 App
- 數組助手 Arr
- 打印輸出 D
- 函數助手 Func
- HTML助手 H5
- HTTP助手 Http
- 數學 Math
- 數字助手 Num
- 正則 RegEx
- 字符串助手 Str
- 日期助手 T
- URL助手 Url
- 工具 Util
- Xml助手 Xml
- HTML組件
- yii小部件輸出轉return
- 手風琴
- 下拉菜單
- 輪播圖
- 模態框
- 媒體列表
- 自定義文件上傳