bootstrap实现自定义按钮导出Excel表格

1.bootstrap动态生成需要导出的表格

导包:

<script type="text/javascript" src="${link.contextPath}/js/jquery.min.js"></script>
	
<!-- bootstrap的js包 -->
<script type="text/javascript" src="${link.contextPath}/js/bootstrap-3.3.5/js/bootstrap.min.js"></script>

<!-- bootstrap的表格包-->
<script type="text/javascript" src="${link.contextPath}/js/bootstrap-3.3.5/js/bootstrap-table.min.js"></script>
<script type="text/javascript" src="${link.contextPath}/js/bootstrap-3.3.5/js/bootstrap-table-zh-CN.js"></script>



html:

<table id="countTable" class="table table-bordered">
	<caption style="text-align:center;">XXXXX</caption>
	<thead></thead>
	<tbody></tbody>
</table>
初始化操作:

//初始化表格
$("#countTable").bootstrapTable({
	striped: true, 
        columns: [{
    		field: "exceptionDiagnose",
          	title: "异常诊断",
          	align: "center"
        },{
        	field: "routine12LeadCount",
        	title: "常规12导",
        	align: "center"
        },{
        	field: "routine18LeadCount",
        	title: "常规18导",
        	align: "center"
        },{
        	field: "dynamicEcgCount",
        	title: "动态心电",
        	align: "center"
        },{
            field: "allCountsCount",
            title: "总计",
            align: "center"
        }],
        cache: false,  
        formatLoadingMessage: function () {
            return "";
        },
        formatNoMatches: function () {  //没有匹配的结果
            return '无符合条件的记录';
        }
});
加载数据:

asyncPost({
	url: "getExceptionDiagnoseCount.json",
        data: {"startCheckTime":startCheckTime,"endCheckTime":endCheckTime,"options":checkBoxArr},
        async: false,
        dataType : 'json',
        success: function(rst){
        	//为表格动态加载数据
        	$("#countTable").bootstrapTable('load',rst.data);
        	
        }
});
表格图:


2.bootstrap自定义按钮导出表格(重点)

(1)导包:

<!-- bootstrap表格导出初始化-->
<script type="text/javascript" src="${link.contextPath}/js/bootstrap-3.3.5/js/bootstrap-table-export/table-export.js"></script>
<!-- bootstrap表格导出执行-->
<script type="text/javascript" src="${link.contextPath}/js/bootstrap-3.3.5/js/bootstrap-table-export/tableExport.js"></script>
<script type="text/javascript" src="${link.contextPath}/js/bootstrap-3.3.5/js/bootstrap-table-export/jquery.base64.js"></script>
<script type="text/javascript" src="${link.contextPath}/js/bootstrap-3.3.5/js/bootstrap-table-export/main.js"></script>
(2)编辑table-export.js包:

var TableExport = function() {
	"use strict";
	// function to initiate HTML Table Export
	var runTableExportTools = function() {
		$(".export-excel").on("click", function(e) {
			e.preventDefault();
			var exportTable = $(this).data("table");
			var ignoreColumn = $(this).data("ignorecolumn");
			$(exportTable).tableExport({
				type : 'excel',
				escape : 'false',
				ignoreColumn : '[' + ignoreColumn + ']'
			});
		});
	};
	return {
		// main function to initiate template pages
		init : function() {
			runTableExportTools();
			//runDataTable_example2();
		}
	};
}(jQuery);

(3)自定义按钮控件:

<button id="exportBtn" class="export-excel btn btn-default" data-table="#countTable">导出</button>

注意:类名需要为export-excel,要不就修改上面table-export.js文件中获取的控件


(4)注意需要在整个页面加载的时候初始化table-export.js文件中的变量TableExport

TableExport.init();

3.结果



4.js包下载



  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值