Exporting a dojo datagrid to a CSV file(将 dojo 数据网格导出到 CSV 文件)
问题描述
我正在寻找一个 Javascript 函数,它将我的数据网格 (zero.grid.DataGrid) 中的数据导出到一个 CSV 文件或可以由电子表格应用程序打开的类似文件中.
I am looking to get a Javascript function which will export my datagrid (zero.grid.DataGrid) full of data into a CSV file or something similar which can be opened by a spreadsheet application.
有没有标准的方法可以做到这一点..
Is there any standard way of doing this out there..
推荐答案
我很难将 Exporter 插件与 EnhancedGrid 一起使用,并使用 servlet 作为后端.最后我使用 iFrame 使它工作:
I had tough time with using Exporter plugin with EnhancedGrid using servlet as backend. Finally I made it work by using iFrame:
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CISROMM - Master Milestone List Editor</title>
<!-- Include dojo dependencies -->
<link rel="stylesheet" href="js/dojoroot/dojo/resources/dojo.css">
<link rel="stylesheet" href="js/dojoroot/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="js/dojoroot/dojox/grid/enhanced/resources/EnhancedGrid_rtl.css">
<link rel="stylesheet" href="js/dojoroot/dojox/grid/enhanced/resources/EnhancedGrid.css">
<link rel="stylesheet" href="js/dojoroot/dojox/grid/resources/claroGrid.css">
<script src="anMvZG9qb3Jvb3QvZG9qby9kb2pvLmpz"
data-dojo-config="isDebug: true,parseOnLoad: true">
</script>
<!-- Include dojo dependencies -->
<!-- Require the widgets -->
<script>
dojo.require("dojox.grid.EnhancedGrid");
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojox.grid.enhanced.plugins.exporter.CSVWriter");
dojo.require("dojo.io.iframe");
<!-- Require the widgets -->
<!-- Data Export Handler -->
function exportAll(){
dijit.byId("grid").exportGrid("csv", function(str){
dojo.io.iframe.create('exportFrame', 'exportFrameLoaded()', '');
dojo.io.iframe._currentDfd = null;
dojo.io.iframe.send({
url: "/ExportGrid.json",
content:{data:str}
});
});
};
<!-- Data Export Handler -->
var grid, store;
<!-- Grid Creation -->
dojo.ready(function(){
store = new dojo.data.ItemFileWriteStore({ url: 'PopulateMsListEditor.json', urlPreventCache: 'yes', clearOnClose: 'yes' });
grid = new dojox.grid.EnhancedGrid({
store: store,
rowSelector: 'auto',
query: {id: "*"} ,
plugins: {
exporter: true
},
structure: [
{field: 'msConstId', width: '20%', name: 'Milestone',hidden: true},
{field: 'name', width: '20%', name: 'Milestone',editable: true}
]
},"grid");
grid.startup();
});
</script>
</head>
<body class="claro">
<button id="exportBtn" data-dojo-type="dijit.form.Button"
data-dojo-props="
iconClass:'dijitIconFile',
showLabel:true,
onClick:function() {
exportAll();
}">
Export to Excel
</button>
<div id="grid" style="width: 560px;height: 680px;"></div>
</body>
</html>
我写了一篇博文,这样我就不必再搜索了.
I have written a blog post so that I don't have to search again.
从 Dojo 中的网格导出数据
PS:建议仅将 iFrame 用于内部/内部 Web 应用程序.
PS: It is recommended to use iFrame only for internal/in-house web applications.
这篇关于将 dojo 数据网格导出到 CSV 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 dojo 数据网格导出到 CSV 文件
- 400或500级别的HTTP响应 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01