jQuery datatable 左上角改粘贴,导出,复制按钮

图一
去除部分
在这里插入图片描述
图二
修改后
在这里插入图片描述
第一步
引入datatable的相关js,css

//css
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css">
//js
<script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>

第二步
引入按钮功能相关js,css

//css
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.6.2/css/buttons.dataTables.min.css">
//js
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.6.2/js/dataTables.buttons.min.js"></script>

ps:添加特殊按钮功能请去官网引入相关js与css
datatable官网参考页https://datatables.net/download/release

第三步
html代码

//css
<table id="example" class="display" style="width:100%">
    <thead>
    <tr>
        <th></th>
        <th >Name</th>
        <th>Position</th>
        <th>Office</th>
        <th>Salary</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <th></th>
        <th>Tiger Nixon</th>
        <th>System Architect</th>
        <th>Edinburgh</th>
        <th>$320,800</th>
    </tr>
    <tr>
        <th></th>
        <th>Tiger Nixon2</th>
        <th>System Architect</th>
        <th>Edinburgh</th>
        <th>$320,800</th>
    </tr>
    </tbody>

    </table>

js代码

//css
$(document).ready(function(){
    var table = $('#example').DataTable( {
        dom: '<"pull-left"B>ft<"pull-left"i>p',
        buttons: [
            {
                text: '<span class="glyphicon glyphicon-save"    title="导出"><font>导出</font></span>',
                extend: 'csv'
            },
            'copy',
        ],
    } );

创建成功

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值