修改Excel导出排序

This commit is contained in:
邹景立 2022-05-05 21:07:23 +08:00
parent b4903935a1
commit 9ecbefac2c
2 changed files with 15 additions and 10 deletions

View File

@ -716,6 +716,16 @@ $(function () {
if (curp > maxp && maxp > 1) $table.trigger('reload', {page: {curr: maxp}}); if (curp > maxp && maxp > 1) $table.trigger('reload', {page: {curr: maxp}});
return res; return res;
}; };
// 搜索表单关联
var sform, search = params.search || table.dataset.targetSearch;
if (search) (sform = $body.find(search)).map(function () {
$(this).attr('data-table-id', table.id);
});
// 绑定选择项关联
var checked = params.checked || table.dataset.targetChecked;
if (checked) $body.find(checked).map(function () {
$(this).attr('data-table-id', table.id);
});
// 实例并绑定事件 // 实例并绑定事件
$table.data('this', layui.table.render(bindData(option))); $table.data('this', layui.table.render(bindData(option)));
$table.bind('reload render reloadData', function (evt, opts) { $table.bind('reload render reloadData', function (evt, opts) {
@ -740,16 +750,6 @@ $(function () {
}).trigger('sort', function (rets) { }).trigger('sort', function (rets) {
(sort = rets), $table.trigger('reload') (sort = rets), $table.trigger('reload')
}); });
// 搜索表单关联对象
var search = params.search || table.dataset.targetSearch;
if (search) $body.find(search).map(function () {
$(this).attr('data-table-id', table.id);
});
// 绑定选择项关联对象
var checked = params.checked || table.dataset.targetChecked;
if (checked) $body.find(checked).map(function () {
$(this).attr('data-table-id', table.id);
});
return $table; return $table;
// 生成初始化参数 // 生成初始化参数
@ -758,6 +758,7 @@ $(function () {
if (sort.field && sort.type) { if (sort.field && sort.type) {
data['_order_'] = sort.type, data['_field_'] = sort.field; data['_order_'] = sort.type, data['_field_'] = sort.field;
options.initSort = {type: sort.type.split(',')[0].split(' ')[0], field: sort.field.split(',')[0].split(' ')[0]}; options.initSort = {type: sort.type.split(',')[0].split(' ')[0], field: sort.field.split(',')[0].split(' ')[0]};
if (sform) $(sform).find('[data-form-export]').attr('data-sort-field', sort.field).attr('data-sort-type', sort.type);
} }
if (options.page === false) options.limit = ''; if (options.page === false) options.limit = '';
return (options['where'] = data), options; return (options['where'] = data), options;

View File

@ -23,6 +23,10 @@ define(function () {
var name = this.dataset.filename || filename; var name = this.dataset.filename || filename;
var method = this.dataset.method || form.attr('method') || 'get'; var method = this.dataset.method || form.attr('method') || 'get';
var location = this.dataset.excel || this.dataset.formExport || form.attr('action') || ''; var location = this.dataset.excel || this.dataset.formExport || form.attr('action') || '';
var sortType = $(this).attr('data-sort-type') || '', sortField = $(this).attr('data-sort-field') || '';
if (sortField.length > 0 && sortType.length > 0) {
location += (location.indexOf('?') > -1 ? '&' : '?') + '_order_=' + sortType + '&_field_=' + sortField;
}
that.load(location, form.serialize(), method).then(function (ret) { that.load(location, form.serialize(), method).then(function (ret) {
that.export(done.call(that, ret, []), name); that.export(done.call(that, ret, []), name);
}).fail(function (ret) { }).fail(function (ret) {