From db0ac015f084fc119764d23ad3b087ec522074e9 Mon Sep 17 00:00:00 2001 From: wolfcode <37436228+wolf-leo@users.noreply.github.com> Date: Tue, 1 Apr 2025 17:35:49 +0800 Subject: [PATCH] feat(easy-admin): add filtering functionality when sorting tables - Implement filter logic in the table sorting event - Iterate through columns to check for filter conditions-Construct filter and operator objects based on selected values - Update the defaultWhere object with filter and op parameters - Reload the table with the combined sorting and filtering conditions --- public/static/plugs/easy-admin/easy-admin.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/public/static/plugs/easy-admin/easy-admin.js b/public/static/plugs/easy-admin/easy-admin.js index da95e09..91cfbf5 100644 --- a/public/static/plugs/easy-admin/easy-admin.js +++ b/public/static/plugs/easy-admin/easy-admin.js @@ -986,7 +986,21 @@ define(["jquery", "tableSelect", "miniTheme", "xmSelect", "lazyload"], function }, listenSort: function (options) { table.on('sort(' + options.layFilter + ')', function (obj) { - let defaultWhere = options.where || {} + let defaultWhere = {} + $.each(options.cols, function (_, colsV) { + let formatFilter = {} + let formatOp = {} + $.each(colsV, function (i, v) { + if (v.field) { + if ($('#c-' + v.field).val()) { + formatFilter[v.field] = $('#c-' + v.field).val() + formatOp[v.field] = v.searchOp || '=' + defaultWhere['filter'] = JSON.stringify(formatFilter); + defaultWhere['op'] = JSON.stringify(formatOp); + } + } + }) + }) let sortWhere = {tableOrder: obj.field + ' ' + obj.type} table.reload(options.id, { where: {...defaultWhere, ...sortWhere}