导出功能如今分为两种模式: static, blob
<table grid-manager="demo-export"></table>
var table = document.querySelector('table[grid-manager="demo-export"]') table.GM({ ajax_url: 'http://www.lovejavascript.com/learnLinkManager/getLearnLinkList' ,ajax_type: 'POST' ,supportAjaxPage: true ,supportExport:true // 配置启用导出功能, 默认即为true ,exportConfig: { // 导出的方式: 默认为static // 1.static: 前端静态导出, 无需后端提供接口,该方式导出的文件并不完美。 // 2.blob: 经过后端接口返回二进制流。`nodejs`可以使用`js-xlsx`, `java`可以使用 `org.apache.poi`生成二进制流。 mode: 'static', // 导出的后缀名 , 默认为`xls` suffix: 'xls', // 导出处理器函数,该函数须要返回一个promise。当`exportType`为`static`时,该参数不生效。 handler: (fileName, query, pageData, sortData, selectedList) => { // 须要经过promise中的resolve()返回二进制流(blob),有两种返回格式: // 1.resolve(blob), 2.resolve({data: blob}) return new Promise(); } } ,query: {pluginId: 1} ,i18n: 'en-us' ,columnData: [ { key: 'name', text: 'name' },{ key: 'info', text: 'info' },{ key: 'url', text: 'url', template: function(url, rowObject){ return '<a style="color:#337ab7;" href="'+url+'" target="_blank">点击跳转</a>'; } },{ key: 'action', remind: 'the action', width: '100px', text: '操做', template: function(action, rowObject){ return '<a style="color:#337ab7;" href="javascript:;" onclick="testEditFN()" learnLink-name="'+rowObject.name+'">编辑</a>'; } } ] });
GridManager.exportGridToXls('demo-export', fileName, onlyChecked)
table: 须要操做的table 或 table的gridManagerName值
fileName: 导出后使用的文件名,若是不设置将使用插件配置项gridManagerName。
onlyChecked:是否仅导出选中的项, 默认为falsejavascript