mirror of
https://gitee.com/layui/layui.git
synced 2026-01-28 19:11:26 +08:00
refactor(table): 重构 defaultToolbar 选项 (#2019)
* test(table): 新增自定义导出示例 * refactor(table): 重构 `defaultToolbar` 选项,增加 `name,onClick` 成员 * refactor: update * Update docs/table/detail/options.md
This commit is contained in:
@@ -153,11 +153,47 @@ layui.use(['table', 'dropdown'], function(){
|
||||
},
|
||||
limit: 30,
|
||||
toolbar: '#toolbarDemo',
|
||||
defaultToolbar: ['filter', 'exports', 'print', {
|
||||
title: '帮助',
|
||||
layEvent: 'LAYTABLE_TIPS',
|
||||
icon: 'layui-icon-tips'
|
||||
}],
|
||||
defaultToolbar: [
|
||||
'filter',
|
||||
{
|
||||
// 自定义导出 --- 2.9.12+
|
||||
name: 'exports',
|
||||
onClick: function(obj) {
|
||||
var data = table.clearCacheKey(obj.data); // 清除临时字段
|
||||
var options = obj.config;
|
||||
|
||||
// 弹出面板
|
||||
obj.openPanel({
|
||||
list: [
|
||||
'<li data-type="csv">导出 CSV 文件</li>',
|
||||
'<li data-type="xlsx">导出 XLSX 文件</li>'
|
||||
].join(''),
|
||||
done: function(panel, list) {
|
||||
list.on('click', function(){
|
||||
var type = $(this).data('type')
|
||||
if (type === 'csv') {
|
||||
table.exportFile(options.id, null, type); // 调用内置导出方法
|
||||
} else if(type === 'xlsx') {
|
||||
// 自助处理导出 - 如借助 sheetjs 库或服务端导出
|
||||
// …
|
||||
layer.msg('自助处理导出 xlsx');
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
'print',
|
||||
{
|
||||
title: '帮助',
|
||||
layEvent: 'LAYTABLE_TIPS',
|
||||
icon: 'layui-icon-tips',
|
||||
onClick: function(obj) {
|
||||
layer.alert('Table for layui-v'+ layui.v);
|
||||
}
|
||||
}
|
||||
],
|
||||
// escape: false,
|
||||
editTrigger: 'dblclick',
|
||||
// cellMaxWidth: 320
|
||||
@@ -470,9 +506,6 @@ layui.use(['table', 'dropdown'], function(){
|
||||
});
|
||||
layer.msg('已设为单行');
|
||||
break;
|
||||
case 'LAYTABLE_TIPS':
|
||||
layer.alert('Table for layui-v'+ layui.v);
|
||||
break;
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user