feat(admin): add table order sorting functionality
初始化表格排序,js排序操作传递到服务端
This commit is contained in:
@@ -88,9 +88,24 @@ class AdminController extends BaseController
|
||||
parent::initialize();
|
||||
$this->adminUid = request()->adminUserInfo['id'] ?? 0;
|
||||
$this->isDemo = env('EASYADMIN.IS_DEMO', false);
|
||||
$this->setOrder();
|
||||
$this->viewInit();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化排序
|
||||
* @return $this
|
||||
*/
|
||||
public function setOrder(): static
|
||||
{
|
||||
$tableOrder = $this->request->param('tableOrder/s', '');
|
||||
if (!empty($tableOrder)) {
|
||||
[$orderField, $orderType] = explode(' ', $tableOrder);
|
||||
$this->sort = [$orderField => $orderType];
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模板变量赋值
|
||||
* @param array|string $name 模板变量
|
||||
|
||||
@@ -272,6 +272,9 @@ define(["jquery", "tableSelect"], function ($, tableSelect) {
|
||||
// 监听表格开关切换
|
||||
admin.table.listenEdit(options.init, options.layFilter, options.id, options.modifyReload);
|
||||
|
||||
// 监听表格排序
|
||||
admin.table.listenSort(options);
|
||||
|
||||
return newTable;
|
||||
},
|
||||
renderToolbar: function (data, elem, tableId, init) {
|
||||
@@ -898,6 +901,15 @@ define(["jquery", "tableSelect"], function ($, tableSelect) {
|
||||
});
|
||||
}
|
||||
},
|
||||
listenSort: function (options) {
|
||||
table.on('sort(' + options.layFilter + ')', function (obj) {
|
||||
let defaultWhere = options.where || {}
|
||||
let sortWhere = {tableOrder: obj.field + ' ' + obj.type}
|
||||
table.reload(options.id, {
|
||||
where: {...defaultWhere, ...sortWhere}
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
checkMobile: function () {
|
||||
var userAgentInfo = navigator.userAgent;
|
||||
|
||||
Reference in New Issue
Block a user