Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ExportData - Custom rendering - Pagination

    Hi Isomorphic,

    I have succeed to export data from a ListGrid in csv, and applying a custom rendering on columns. This export is returning to the client for "Download".

    I would like to know if is it possible to do this with a sort a pagination. This to avoid having memory error / performance leak on the server.

    The way I call the export :
    Code:
    final DSRequest dsRequestProperties = new DSRequest();
    dsRequestProperties.setExportAs("csv");
    dsRequestProperties.setExportDisplay(ExportDisplay.DOWNLOAD);
    dsRequestProperties.setExportDatesAsFormattedString(true);
    dsRequestProperties.setOperationId("export");
    dsRequestProperties.setOperationType(DSOperationType.FETCH);
    
    grid.exportData(dsRequestProperties);
    This export will call a specific method to customize the data
    Code:
    <operationBinding operationType="fetch" operationId="export" dropExtraFields="false">
    	<serverObject lookupStyle="new" className="com.server.dmi.BaseServerObject" methodName="exportCustomers"/>
    </operationBinding>
    Code:
    public DSResponse exportCustomers(DSRequest dsRequest, HttpServletRequest servletRequest) throws Exception {
    	DataSource dataSource = DataSourceManager.get("dataSource"));
    	Map criteria = dsRequest.getCriteria();
    
    	DSRequest pagRequest = new DSRequest();
    	pagRequest.setDataSource(dataSource);
    	pagRequest.setCriteria(criteria);
    	pagRequest.setOperationType("fetch");
    
    	final DSResponse pagResponse = pagRequest.execute();
    	List<Map<String, Object>> datas = (List<Map<String, Object>>)pagResponse.getData();
    	for (Map<String, Object> data : datas) {
    		data.put("CLASSIFICATION",Localization.translate(servletRequest.getLocale(),(String)data.get("CLASSIFICATION")));
    	}
    	return pagResponse;
    }
    What I try to do is to have a pagination in the pagRequest.execute() that will return a set of the date to export, and a way to specify to the exportData that the data returned in the response is paginated and the method must be recall.

    Is there a way to do this?

    Regards

    Julien

    #2
    Setting dsRequest.streamResults results in a streaming export when you use SQLDataSource, but this is of course only possible if you don't implement a DMI that explicitly iterates through all the records.

    In 5.0, there are new server-side APIs you can implement (DSResponse.hasNextRecord() and nextRecordAsObject()) to implement a streaming export with custom logic like you've shown. You would return a subclass of DSResponse where you have implemented hasNextRecord() and nextRecordAsObject() to call the same APIs on the original DSResponse, but modify the result before returning it.

    Comment


      #3
      Ok I can use a SQLDataSource, but how can I execute an operation on each record.
      Is the query will be paginated?

      Comment


        #4
        ? We just answered that:

        In 5.0, there are new server-side APIs you can implement (DSResponse.hasNextRecord() and nextRecordAsObject()) to implement a streaming export with custom logic like you've shown. You would return a subclass of DSResponse where you have implemented hasNextRecord() and nextRecordAsObject() to call the same APIs on the original DSResponse, but modify the result before returning it.

        Comment

        Working...
        X