如何解决从 Shield UI Grid 导出所有记录
我正在尝试从数据网格中导出所有数据。盾牌 UI 示例演示确实导出了所有记录,所以我知道它可以完成!当我这样做时,它只导出当前页面数据!
Java 代码片段:
remote: {
read: {
type: "POST",url: "/portals/ajax"
}
}
});
$("#manageportalsgrid").shieldGrid({
dataSource: portals,sorting: {
multiple: true
},selection: {
type: "row",multiple: true,toggle: false
},filtering: {
enabled: true
},paging: true,columns: [
{ field: "portalID",width: "130px",title: "Portal ID" },{ field: "overx",title: "Overworld X" },{ field: "overy",title: "Overworld Y" },{ field: "overz",title: "Overworld Z" },{ field: "netherx",title: "Nether X" },{ field: "nethery",title: "Nether Y" },{ field: "netherz",title: "Nether Z" },{ field: "portalowner",title: "Portal Owner"},{ field: "description",title: 'Portal Description'},{
field:"actions",width: "200px",title:"Actions",columnTemplate: $("#portalEditTemplate").html() + $("#portalDeleteTemplate").html()
}
],toolbar: [
{
buttons: [
{
commandName: "csv",caption: '<span class="sui-sprite sui-grid-icon-export-csv"></span> <span class="sui-grid-button-text">Export to CSV</span>'
}
]
}
],exportOptions: {
proxy: "/attachments/save",csv: {
fileName: "Viikis Community Server portals " + getMonthforFile(),dataSource: portals,readDataSource: true
}
}
});
function getMonthforFile(){
var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
var now = new Date();
var thisMonth = months[now.getMonth()];
var year = now.getFullYear();
var monthyear = thisMonth +' ' + year;
return monthyear;
}
数据源调用生成数据源的php脚本,输出:
[{"portalID":"2","netherx":"63","nethery":"32","netherz":"-69","overx":"500","overy":"59","overz":"-550","description":"Carley_Guys Base","owner":"2","userID":"2","portalowner":"carley_guy"},{"portalID":"3","netherx":"66","netherz":"112","overx":"531","overy":"57","overz":"892","description":"Krons Portal","owner":"3","userID":"3","portalowner":"Kron"},{"portalID":"4","netherx":"-19","netherz":"-79","overx":"-150","overy":"64","overz":"-629","description":"Rosysian's Home","owner":"4","userID":"4","portalowner":"Rosysian"},{"portalID":"5","netherx":"-22","netherz":"97","overx":"-178","overz":"776","description":"Budmeister's Portal","owner":"5","userID":"5","portalowner":"Budmeister91"},{"portalID":"6","netherx":"100","netherz":"51","overx":"796","overy":"53","overz":"406","description":"Tired_Luvs Portal","owner":"6","userID":"6","portalowner":"Tired_Luvs"},{"portalID":"7","netherx":"47","nethery":"56","netherz":"-68","overx":"378","overz":"-547","description":"","owner":"7","userID":"7","portalowner":"EdenShieldex"},{"portalID":"9","netherx":"50","netherz":"11","overx":"401","overy":"80","overz":"89","owner":"10","userID":"10","portalowner":"thewookie0"},{"portalID":"10","netherx":"165","nethery":"35","netherz":"139","overx":"1317","overy":"63","overz":"1113","description":"Viikis Jungle Portal","owner":"8","userID":"8","portalowner":"Viiki"},{"portalID":"11","netherx":"333","netherz":"331","overx":"2661","overy":"68","overz":"2650","description":"Dummy Portal Beths Adventure",{"portalID":"12","netherx":"-32","netherz":"43","overx":"-256","overy":"81","overz":"340","description":"egidasha's portal","owner":"31","userID":"31","portalowner":"egidasha"},{"portalID":"13","netherx":"-58","nethery":"34","netherz":"-7","overx":"-464","overy":"71","overz":"-52","description":"Psylences Portal","owner":"23","userID":"23","portalowner":"Psylence33"},{"portalID":"14","netherx":"-33","netherz":"25","overx":"-262","overy":"77","overz":"199","description":"Viikis Portal Near Spawn",{"portalID":"15","netherx":"-41","netherz":"26","overx":"-330","overz":"206","description":"Pengdonuts Portal","owner":"19","userID":"19","portalowner":"PengDonut"},{"portalID":"16","netherx":"-24","netherz":"-112","overx":"-193","overz":"-898","description":"RocWolfes Portal","owner":"14","userID":"14","portalowner":"RocWolfe"},{"portalID":"17","netherx":"32","netherz":"-133","overx":"256","overz":"-1066","description":"MysteryMuffins' Portal","owner":"11","userID":"11","portalowner":"meepymuffins"},{"portalID":"18","netherz":"83","overy":"105","overz":"663","description":"Moi33","owner":"25","userID":"25","portalowner":"MoiXtra"},{"portalID":"19","netherx":"-56","netherz":"21","overx":"-450","overy":"51","overz":"166","description":"Jerv's Portal","owner":"21","userID":"21","portalowner":"jervi_servi"},{"portalID":"20","netherx":"19","netherz":"12","overx":"154","overy":"66","overz":"98","description":"Br3admakesufat's Portal","owner":"24","userID":"24","portalowner":"BR3ADMAKESUFAT"},{"portalID":"22","netherx":"96","netherz":"113","overx":"771","overy":"65","overz":"906","description":"BentlyEU's Portal","owner":"26","userID":"26","portalowner":"bentley"},{"portalID":"23","netherx":"60","netherz":"78","overx":"483","overz":"621","description":"hozbombs Portal","owner":"29","userID":"29","portalowner":"hozbomb"},{"portalID":"24","netherx":"-8","netherz":"5","overx":"-64","overy":"96","overz":"36","description":"sushis Portal","owner":"27","userID":"27","portalowner":"thereal_sushi"},{"portalID":"25","netherx":"-64","netherz":"68","overx":"-509","overy":"72","overz":"547","description":"ikxrleys Portal","owner":"32","userID":"32","portalowner":"ikxrley"},{"portalID":"26","netherx":"-67","netherz":"-6","overx":"-532","overz":"-46","description":"wizard1011's Portal","owner":"30","userID":"30","portalowner":"superswag3211"},{"portalID":"27","netherx":"-50","netherz":"41","overx":"-400","overz":"324","description":"WW__WW's Portal",{"portalID":"28","netherx":"-44","netherz":"6","overx":"-352","overy":"67","overz":"51","description":"hippert02s Portal","owner":"33","userID":"33","portalowner":"hippert"},{"portalID":"29","netherx":"67","netherz":"50","overx":"535","overz":"398","description":"FaithfulSO3s Portal","owner":"28","userID":"28","portalowner":"ixfaithful"},{"portalID":"30","netherx":"156","netherz":"143","overx":"1245","overy":"11","overz":"1141","description":"Bud's Jungle Portal",{"portalID":"31","netherx":"192","netherz":"-252","overx":"1532","overz":"-2013","description":"VirusBB8's base","owner":"17","userID":"17","portalowner":"VirusBB8"},{"portalID":"32","netherx":"-150","netherz":"-151","overx":"-1197","overy":"22","overz":"-1205","description":"End Portal Room",{"portalID":"34","netherx":"244","netherz":"249","overx":"1950","overz":"1993","description":"NorwegianGreaser Home","owner":"22","userID":"22","portalowner":"NorwegianGreaser"},{"portalID":"35","nethery":"15","netherz":"54","overx":"-172","overy":"75","overz":"430","description":"LordPapi_s Portal","owner":"12","userID":"12","portalowner":"Lordpapi_"},{"portalID":"36","netherx":"642","netherz":"633","overx":"5133","overy":"70","overz":"5067","description":"Middle of the sea",{"portalID":"37","netherx":"548","netherz":"272","overx":"4385","overz":"2172","description":"Desert into soul sand valley","owner":"35","userID":"35","portalowner":"iamtehnub"},{"portalID":"38","netherx":"140","netherz":"56","overx":"1123","overz":"450","description":"Mountain biome port",{"portalID":"39","netherx":"405","netherz":"219","overx":"3237","overz":"1753",{"portalID":"43","netherx":"-110","netherz":"-130","overx":"-880","overy":"97","overz":"-1040","description":"TmacMusic's Base","owner":"1","userID":"1","portalowner":"TmacMusic"}]
这里是管理门户视图代码
<?php require APPROOT . '/views/inc/header.php'; ?>
<h1><?php echo $data['title']; ?></h1>
<div id="adminFlex">
<?php require APPROOT . '/views/inc/navadmin.php'; ?>
<div id="adminDashBoard" class="dashboard">
<script type="text/x-shield-template" id="portalEditTemplate">
<a class="btn btn-info" href="/portals/edit/{portalID}">Edit</a>
</script>
<script type="text/x-shield-template" id="portalDeleteTemplate">
<button type="button" class="btn btn-danger" id="delete" data-target="#confirmDeletePortal" data-toggle="modal" data-portalid="{portalID}">Delete</button>
</script>
<div class="row">
<div id="manageportalsgrid" class="center">
</div>
<button class="btn-info" onclick="refreshManagePortalData()">Refresh Portals</button>
<button class="btn-danger" data-target="#confirmDeleteAllPortals" data-toggle="modal">Delete All Portals</button>
</div>
<!-- Delete portal by ID Modal -->
<div class="modal fade" id="confirmDeletePortal" tabindex="-1" role="dialog" aria-labelledby="confirmDeletePortalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="confirmDeletePortalLabel">Delete portal?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this portal?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
<form action="<?php echo URLROOT; ?>portals/delete/" method=post>
<input type="hidden" id="delportalID" name="portalID" value="">
<input type="submit" class="btn btn-danger" name="action" value="delete"/>
</form>
</div>
</div>
</div>
</div>
<!-- Delete All Portals Modal -->
<div class="modal fade" id="confirmDeleteAllPortals" tabindex="-1" role="dialog" aria-labelledby="confirmDeleteAllPortalsLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="confirmDeleteAllPortalsModalLabel">Delete All Portals?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Are you sure you want to delete all the portals?
</div>
<div class="modal-footer">
<form action="<?php echo URLROOT; ?>portals/clear/" method=post>
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
<input type="submit" name="yes" value="yes" class="btn btn-primary"/>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<?php require APPROOT . '/views/inc/footer.php'; ?>
我的问题是它只导出当前页面,而不是整个记录集。文档说你应该将 readDataSource 设置为 true 才能这样做,但它不起作用。
在此先感谢您的帮助。
解决方法
如果数据源和/或它们的变量相同,我认为 readDataSource 选项将被忽略。我复制了门户数据源并制作了副本导出门户,如下所示:
var portals = new shield.DataSource({
remote: {
read: {
type: "POST",url: "/portals/ajax"
}
}
});
var exportportals = new shield.DataSource({
remote: {
read: {
type: "POST",url: "/portals/ajax"
}
}
});
然后我分别更改了网格的数据源和导出的数据源:
$("#manageportalsgrid").shieldGrid({
dataSource: portals,sorting: {
multiple: true
},selection: {
type: "row",multiple: true,toggle: false
},filtering: {
enabled: true
},paging: true,columns: [
{ field: "portalID",width: "130px",title: "Portal ID" },{ field: "overx",title: "Overworld X" },{ field: "overy",title: "Overworld Y" },{ field: "overz",title: "Overworld Z" },{ field: "netherx",title: "Nether X" },{ field: "nethery",title: "Nether Y" },{ field: "netherz",title: "Nether Z" },{ field: "portalowner",title: "Portal Owner"},{ field: "description",title: 'Portal Description'},{
field:"actions",width: "200px",title:"Actions",columnTemplate: $("#portalEditTemplate").html() + $("#portalDeleteTemplate").html()
}
],toolbar: [
{
buttons: [
{
commandName: "csv",caption: '<span class="sui-sprite sui-grid-icon-export-csv"></span> <span class="sui-grid-button-text">Export to CSV</span>'
}
]
}
],exportOptions: {
proxy: "/attachments/save",csv: {
fileName: "Viikis Community Server portals " + getMonthforFile(),dataSource: exportportals,readDataSource: true
}
}
});
现在网格显示分页,导出时所有记录都被导出!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。