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="js/dojoroot/dojo/dojo.js"
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 文件
基础教程推荐
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01