excel前端导出(bootstrap-table,tableExport)

场景:bootstrap-table使用了前端分页,tableExport只导出了第一页的数据

bootstrap-table绑定事件(翻页事件,视图重置事件)

onPageChange: function (number, size) {
    table.params = {pageNumber: number, pageSize: size};
    console.info("onPageChange")
},
onResetView: function () {
    console.info("onResetView");
    console.info(table.params)
    if (table.downExcelState) {
        $("#" + table.bstableId).tableExport({
            type: 'excel',
            escape: false,
            fileName: table.fileName,
            ignoreColumn: table.ignoreColumn
        });
        table.downExcelState = false;
        console.info(table.params)
        table.btInstance.bootstrapTable('refresh', table.params);
    }
}

bootstrap-table添加下载文件方法

/**
 * 前台下载excel
 * fileName excel文件名
 * ignoreColumn 不需要导出的列
 */
downExcel: function (fileName, ignoreColumn) {
    this.fileName = fileName;
    this.ignoreColumn = ignoreColumn;
    this.btInstance.bootstrapTable('refresh', {pageNumber: 1, pageSize: 999999999999});
    this.downExcelState = true;
}

使用

Operation.table.downExcel("立案案件",[10]);

tableExport源码 https://pan.baidu.com/s/1o83NpYq
bootstrap-table源码 https://pan.baidu.com/s/1bpDDiFl

你可能感兴趣的:(JS)