layui table点击单元格复制单元格里的内容,目前加clipboard.min.js也未实现。
```html
<script src="../js/clipboard.min.js" charset="utf-8"></script>
<script src="../layui-soul-table-master/layui/layui.js"></script>
<script>
layui.config({
base: '../layui-soul-table-master/ext/', // 模块目录
version: 'v1.8.0'
}).extend({ // 模块别名
soulTable: 'soulTable',
shortcut: 'shortcut',
tableChild: 'tableChild',
tableMerge: 'tableMerge',
tableFilter: 'tableFilter',
excel: 'excel'
});
layui.use(['jquery','form', 'table','soulTable','tableFilter'], function () {
var table = layui.table,
soulTable = layui.soulTable,
tableFilter = layui.tableFilter;
table.render({
elem: '#myTable2'
,url: './data.php' //数据接口
,height: getContainerHtwo('#two')-12
,page: false
,cellMinWidth: 80
,cols: [[
{field: 'id', title: 'ID',sort: true}
,{field: 'name', title: 'SN',sort: true, filter: true, templet:function (d) {
return '<a href="javascript:;" data-clipboard-text="" class="font-primary" title="点击复制" lay-event="copyname">'+d.name+'</a>';
}, unresize: true, align: 'center'}
]]
,done: function (res,count) {
soulTable.render(this)
}
,filter: {
bottom: false
}
});
//清空筛选
$('#clear').click(function (obj) {
//if (obj.event === 'clearFilter') {
// 清除所有筛选条件并重载表格
// 参数: tableId
soulTable.clearFilter('myTable2')
//}
});
/* 表格工具条点击事件 */
table.on('tool(myTable2)', function (obj) {
var data = obj.data;
var layEvent = obj.event;
if (layEvent === 'copyname') {
$(".font-primary").attr("data-clipboard-text",data.name);
var clipboard = new ClipboardJS('.font-primary');
clipboard.on('success', function(e) {
alert('复制成功');
clipboard.destroy(); //解决多次弹窗
e.clearSelection();
});
}
});
```