Fastadmin表格的导出功能

table.bootstrapTable({
  ...
    showExport: true,
    exportTypes:['excel'],
    exportDataType: "all",  //可用值 all 当前搜索条件下所有的可见列的数据  selected 选中行的数据  basic 当前分页下的数据
    exportOptions: {
    	fileName: '自定义导出文件名'+ Moment().format("YYYY-MM-DD"),
    	htmlContent: true,
        ignoreColumn: [0, -1], // 忽略第一列和最后一列
        // ignoreColumn: { ignoreColumn: [0, 'operate', 'avatar'] //默认不导出第一列(checkbox)与操作(operate)列 },
        mso: {
            //修复导出数字不显示为科学计数法
            onMsoNumberFormat: function (cell, row, col) {
                return !isNaN($(cell).text())?'\\@':'';
            }
        },
        onBeforeSaveToFile: function (data, fileName, type, charset, encoding, bom) {
			return $.fn.bootstrapTable.defaults.extend.savestatus;
		},
        // 处理导出图片
	    onCellHtmlData: function ($cell, row, col, htmlData) {
	        var html = $.parseHTML(htmlData);
	        var inputidx = 0;
	        var selectidx = 0;
	
	        var result = '';
	        $.each(html, function () {
	            if ($(this).is("input")) {
	                result += $cell.find('input').eq(inputidx++).val();
	            }
	            else if ($(this).is("select")) {
	                result += $cell.find('select option:selected').eq(selectidx++).text();
	            }
	            else if ($(this).is("img")) {
	                var src = $(this).attr('src');
	                if (src.indexOf('http') === -1) {
	                    $(this).attr('src', window.location.origin + src);
	                }
	                $(this).attr("width", "100").attr("height", "100").attr('class', '');
	                result += '<div>' + $(this).get(0).outerHTML + '</div>';
	            } else {
	                if (typeof $(this).html() === 'undefined') {
	                    result += $(this).text();
	                }
	                else if (jQuery().bootstrapTable === undefined ||
	                    ($(this).hasClass('filterControl') !== true &&
	                        $cell.parents('.detail-view').length === 0)) {
	                    result += $(this).html();
	                }
	            }
	        });
	        return result;
	    },
	    onCellHtmlHyperlink: function ($cell, rowIndex, colIndex, href, htmlData) {
	        var html = $.parseHTML(htmlData);
	        var inputidx = 0;
	        var selectidx = 0;
	        var result = '';
	
	        $.each(html, function () {
	            if ($(this).is("input")) {
	                result += $cell.find('input').eq(inputidx++).val();
	            } else if ($(this).is("select")) {
	                result += $cell.find('select option:selected').eq(selectidx++).text();
	            } else if ($(this).is("img")) {
	                var src = $(this).attr('src');
	                if (src.indexOf('http') === -1) {
	                    $(this).attr('src', window.location.origin + src);
	                }
	                $(this).attr("width", "40").attr("height", "40").attr('class', '');
	                result += '<div>' + $(this).get(0).outerHTML + '</div>';
	            } else {
	                if (typeof $(this).html() === 'undefined') {
	                    result += $(this).text();
	                } else if (jQuery().bootstrapTable === undefined ||
	                    ($(this).hasClass('filterControl') !== true &&
	                        $cell.parents('.detail-view').length === 0)) {
	                    result += $(this).html();
	                }
	            }
	        });
	        return result;
	    }
    },
...
)

“@” 强制为文本格式
“0” 数字 无小数
“0.000” 数字 三位小数
“0%” 百分比 无小数
“Percent” 百分比 两位小数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值