1

I am trying to export all data from a data grid. The shield UI example demo does export all records so I know it can be done! When I do it, it only exports the current pages data!

Java code snippets:

    
    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", width: "130px", title: "Overworld X" },
                { field: "overy", width: "130px", title: "Overworld Y" },
                { field: "overz", width: "130px", title: "Overworld Z" },
                { field: "netherx", width: "130px", title: "Nether X" },
                { field: "nethery", width: "130px", title: "Nether Y" },
                { field: "netherz", width: "130px", title: "Nether Z" },
                { field: "portalowner", width: "130px", title: "Portal Owner"},
                { field: "description", width: "130px", 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;

}

the datasource calls a php script that generates the data source, which outputs:

[{"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","nethery":"32","netherz":"112","overx":"531","overy":"57","overz":"892","description":"Krons Portal","owner":"3","userID":"3","portalowner":"Kron"},{"portalID":"4","netherx":"-19","nethery":"32","netherz":"-79","overx":"-150","overy":"64","overz":"-629","description":"Rosysian's Home","owner":"4","userID":"4","portalowner":"Rosysian"},{"portalID":"5","netherx":"-22","nethery":"32","netherz":"97","overx":"-178","overy":"59","overz":"776","description":"Budmeister's Portal","owner":"5","userID":"5","portalowner":"Budmeister91"},{"portalID":"6","netherx":"100","nethery":"32","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","overy":"53","overz":"-547","description":"","owner":"7","userID":"7","portalowner":"EdenShieldex"},{"portalID":"9","netherx":"50","nethery":"32","netherz":"11","overx":"401","overy":"80","overz":"89","description":"","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","nethery":"32","netherz":"331","overx":"2661","overy":"68","overz":"2650","description":"Dummy Portal Beths Adventure","owner":"6","userID":"6","portalowner":"Tired_Luvs"},{"portalID":"12","netherx":"-32","nethery":"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","nethery":"32","netherz":"25","overx":"-262","overy":"77","overz":"199","description":"Viikis Portal Near Spawn","owner":"8","userID":"8","portalowner":"Viiki"},{"portalID":"15","netherx":"-41","nethery":"32","netherz":"26","overx":"-330","overy":"64","overz":"206","description":"Pengdonuts Portal","owner":"19","userID":"19","portalowner":"PengDonut"},{"portalID":"16","netherx":"-24","nethery":"32","netherz":"-112","overx":"-193","overy":"63","overz":"-898","description":"RocWolfes Portal","owner":"14","userID":"14","portalowner":"RocWolfe"},{"portalID":"17","netherx":"32","nethery":"32","netherz":"-133","overx":"256","overy":"59","overz":"-1066","description":"MysteryMuffins' Portal","owner":"11","userID":"11","portalowner":"meepymuffins"},{"portalID":"18","netherx":"-24","nethery":"32","netherz":"83","overx":"-193","overy":"105","overz":"663","description":"Moi33","owner":"25","userID":"25","portalowner":"MoiXtra"},{"portalID":"19","netherx":"-56","nethery":"32","netherz":"21","overx":"-450","overy":"51","overz":"166","description":"Jerv's Portal","owner":"21","userID":"21","portalowner":"jervi_servi"},{"portalID":"20","netherx":"19","nethery":"32","netherz":"12","overx":"154","overy":"66","overz":"98","description":"Br3admakesufat's Portal","owner":"24","userID":"24","portalowner":"BR3ADMAKESUFAT"},{"portalID":"22","netherx":"96","nethery":"32","netherz":"113","overx":"771","overy":"65","overz":"906","description":"BentlyEU's Portal","owner":"26","userID":"26","portalowner":"bentley"},{"portalID":"23","netherx":"60","nethery":"32","netherz":"78","overx":"483","overy":"63","overz":"621","description":"hozbombs Portal","owner":"29","userID":"29","portalowner":"hozbomb"},{"portalID":"24","netherx":"-8","nethery":"32","netherz":"5","overx":"-64","overy":"96","overz":"36","description":"sushis Portal","owner":"27","userID":"27","portalowner":"thereal_sushi"},{"portalID":"25","netherx":"-64","nethery":"32","netherz":"68","overx":"-509","overy":"72","overz":"547","description":"ikxrleys Portal","owner":"32","userID":"32","portalowner":"ikxrley"},{"portalID":"26","netherx":"-67","nethery":"32","netherz":"-6","overx":"-532","overy":"64","overz":"-46","description":"wizard1011's Portal","owner":"30","userID":"30","portalowner":"superswag3211"},{"portalID":"27","netherx":"-50","nethery":"32","netherz":"41","overx":"-400","overy":"66","overz":"324","description":"WW__WW's Portal","owner":"29","userID":"29","portalowner":"hozbomb"},{"portalID":"28","netherx":"-44","nethery":"32","netherz":"6","overx":"-352","overy":"67","overz":"51","description":"hippert02s Portal","owner":"33","userID":"33","portalowner":"hippert"},{"portalID":"29","netherx":"67","nethery":"32","netherz":"50","overx":"535","overy":"65","overz":"398","description":"FaithfulSO3s Portal","owner":"28","userID":"28","portalowner":"ixfaithful"},{"portalID":"30","netherx":"156","nethery":"32","netherz":"143","overx":"1245","overy":"11","overz":"1141","description":"Bud's Jungle Portal","owner":"5","userID":"5","portalowner":"Budmeister91"},{"portalID":"31","netherx":"192","nethery":"32","netherz":"-252","overx":"1532","overy":"65","overz":"-2013","description":"VirusBB8's base","owner":"17","userID":"17","portalowner":"VirusBB8"},{"portalID":"32","netherx":"-150","nethery":"32","netherz":"-151","overx":"-1197","overy":"22","overz":"-1205","description":"End Portal Room","owner":"3","userID":"3","portalowner":"Kron"},{"portalID":"34","netherx":"244","nethery":"32","netherz":"249","overx":"1950","overy":"68","overz":"1993","description":"NorwegianGreaser Home","owner":"22","userID":"22","portalowner":"NorwegianGreaser"},{"portalID":"35","netherx":"-22","nethery":"15","netherz":"54","overx":"-172","overy":"75","overz":"430","description":"LordPapi_s Portal","owner":"12","userID":"12","portalowner":"Lordpapi_"},{"portalID":"36","netherx":"642","nethery":"32","netherz":"633","overx":"5133","overy":"70","overz":"5067","description":"Middle of the sea","owner":"22","userID":"22","portalowner":"NorwegianGreaser"},{"portalID":"37","netherx":"548","nethery":"32","netherz":"272","overx":"4385","overy":"70","overz":"2172","description":"Desert into soul sand valley","owner":"35","userID":"35","portalowner":"iamtehnub"},{"portalID":"38","netherx":"140","nethery":"32","netherz":"56","overx":"1123","overy":"70","overz":"450","description":"Mountain biome port","owner":"35","userID":"35","portalowner":"iamtehnub"},{"portalID":"39","netherx":"405","nethery":"32","netherz":"219","overx":"3237","overy":"65","overz":"1753","description":"","owner":"22","userID":"22","portalowner":"NorwegianGreaser"},{"portalID":"43","netherx":"-110","nethery":"32","netherz":"-130","overx":"-880","overy":"97","overz":"-1040","description":"TmacMusic's Base","owner":"1","userID":"1","portalowner":"TmacMusic"}]

Here is the manage portal view code

<?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">&times;</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">&times;</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'; ?>

My issue is that it only ever exports the current page, not the entire record set. The documentation says you should set the readDataSource to true for it to do so, but it's not working.

Thanks in advance for any help.

timmac15
  • 59
  • 3

1 Answers1

1

I think the readDataSource option is ignored if the datasources and or their variables are Identical. I duplicated the the portals datasource and made the copy exportportals like so:

var portals = new shield.DataSource({
    
    remote: {
        read: {
            type: "POST",
            url: "/portals/ajax"
        }
    }
});

var exportportals = new shield.DataSource({
    
    remote: {
        read: {
            type: "POST",
            url: "/portals/ajax"
        }
    }
});

Then I changed the dataSources for the grid and the export dataSources respectively:

$("#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", width: "130px", title: "Overworld X" },
                { field: "overy", width: "130px", title: "Overworld Y" },
                { field: "overz", width: "130px", title: "Overworld Z" },
                { field: "netherx", width: "130px", title: "Nether X" },
                { field: "nethery", width: "130px", title: "Nether Y" },
                { field: "netherz", width: "130px", title: "Nether Z" },
                { field: "portalowner", width: "130px", title: "Portal Owner"},
                { field: "description", width: "130px", 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
                }
                
            }
        });

Now the Grid shows with the pagination and when exporting all the records get exported!

timmac15
  • 59
  • 3