Announcement

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

    Excel Export not working

    Hi,

    I am using SmartGWTPro 3.0 and Google Chrome version 16.0.

    I tried to export the grid contents to CSV file. But I am unable to do so.
    I found that, on clicking export button, the application sends a POST request to the server.

    The code for export data is
    Code:
     
    DeviceListDS dataSource = new DeviceListDS();
    
    final ListGrid deviceGrid = new ListGrid();
    deviceGrid.setShowFilterEditor(true);
    deviceGrid.setFilterOnKeypress(true);
    deviceGrid.setDataSource(dataSource);
    deviceGrid.setWidth100();
    deviceGrid.setHeight(200);
    deviceGrid.setAutoFetchData(true);
    
    IButton exportButton = new IButton();
    exportButton.setTitle("Export");
    exportButton.addClickHandler(new ClickHandler() {
    	@Override
    	public void onClick(ClickEvent event) {
    	      DSRequest dsRequestProperties = new DSRequest();  
                  dsRequestProperties.setExportAs(ExportFormat.CSV); 
    	      dsRequestProperties.setExportDisplay(ExportDisplay.DOWNLOAD);
    	      deviceGrid.exportData(dsRequestProperties);            
    	}
    });
    
    devLayout.addMember(deviceGrid);
    devLayout.addMember(exportButton);
    DataSource is
    Code:
     
    package comd.example.myproject.client.DataSource;
    
    import com.smartgwt.client.data.XJSONDataSource;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.types.DSDataFormat;
    
    public class DeviceListDS extends XJSONDataSource {
    	public DeviceListDS() {
    		setDataFormat(DSDataFormat.JSON);
    		setRecordXPath("deviceList");
    		setDataURL("http://localhost:8080/agentManager/device/device/?groupId=0");
    
    		DataSourceTextField deviceModel = new DataSourceTextField(
    				"deviceModel", "Device Model");
    		DataSourceTextField sysName = new DataSourceTextField("sysName",
    				"Device Name");
    		DataSourceTextField ipAddress = new DataSourceTextField("ipAddress",
    				"IP Address");
    		DataSourceTextField sysLocation = new DataSourceTextField(
    				"sysLocation", "System Location");
    		DataSourceTextField description = new DataSourceTextField(
    				"description", "Description");
    		DataSourceTextField subnetMask = new DataSourceTextField("subnetMask",
    				"SubnetMask");
    		DataSourceTextField statusId = new DataSourceTextField("statusId",
    				"Status Id");
    
    		setFields(deviceModel, sysName, ipAddress, sysLocation, description,
    				subnetMask, statusId);
    	}
    }
    What could be the issue ?
    Mainly I need to export the data which is available in the list grid (client data).

    Any suggestion please ?!!

    #2
    exportData() will only work on a server side dataSource. It is implemented as a special fetch against the dataSource with parameters on the request that the server recognizes and uses to serve back appropriately formatted data.

    You're using an XJSONDataSource here, with a custom dataURL - essentially this is a client-side integration (the SmartGWT server knows nothing about this dataSource).
    As a result 'exportData()' will not be available to you.

    However - you should be able to use exportClientData() on your databound listGrid once your data has been loaded on the client. This requires the SmartGWT server be running but uses it only to perform the csv-formatting of the (already loaded) records. Unlike 'exportData()' it does not require a server-side dataSource to fetch against since the client side data is sent to the server in the request, and csv-formatted data is returned in the response.

    Comment


      #3
      Thanks for the response.

      I changed 'exportData(dsRequestProperties)' to 'exportClientData(dsRequestProperties)',

      On clicking export, it redirects to
      'http://127.0.0.1:8888/testgrid/sc/IDACall?isc_rpc=1&isc_v=SC_SNAPSHOT-2011-12-05&isc_tnum=2'

      and I am getting the following error.

      HTTP ERROR: 404
      NOT_FOUND
      RequestURI=/testgrid/sc/IDACall

      I confirmed that the data has been loaded into the grid. Do I miss something ?

      my Web.xml is
      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
               version="2.5"
               xmlns="http://java.sun.com/xml/ns/javaee">
      
        <!-- Servlets -->
        
        <!-- Default page to serve -->
        <welcome-file-list>
          <welcome-file>TestGrid.html</welcome-file>
        </welcome-file-list>
      
      </web-app>

      Comment


        #4
        You don't have web.xml configured to pick up the IDACall servlet, which is used to process all SmartGWT RPC requests against the SmartGWT server.
        You'll basically need to merge web.xml - easiest to copy the relevant config over from one of the sample projects such as the "Built In DS" sample.

        Check out the docs on setting up a SGWT EE project here: http://www.smartclient.com/smartgwte...wtEESetup.html and the docs on the SmartGWT servlets here:http://www.smartclient.com/smartgwte...etDetails.html

        Comment


          #5
          Thanks.

          I found the mistakes.

          1. web.xml is not configured for IDACall
          2. server.properties is not added

          Comment


            #6
            Hi As i told Excel export working perfectly from listgrid.

            I am using SmartGWTPro 3.0 and Google Chrome version 22 and i am setting RestDataSource to listgrid.

            If i want export data on server side data source listgrid.exportData() method enough or any changes are needed.

            I tried listgrid.exportData() and listgrid.exportData(dsRequestProperties). But there was no luck.

            Below is my code.

            DSRequest dsRequestProperties = new DSRequest();
            dsRequestProperties.setExportAs(ExportFormat.CSV);
            dsRequestProperties.setExportDisplay(ExportDisplay.DOWNLOAD);
            dsRequestProperties.setExportFilename("OperationLog.csv");
            //OperationmLogGrid.exportClientData(dsRequestProperties);
            OperationmLogGrid.exportData();

            Please help me to achieve this.
            Thanks in Advance.
            Last edited by vnathank; 9 Oct 2012, 03:08.

            Comment


              #7
              Hi,
              waiting for your reply.
              can you please update this thread.

              Comment


                #8
                See previous response - exportData() requires a server-side DataSource based on a .ds.xml file. It will not work with RestDataSource or XJSONDataSource. Only exportClientData can be used with such DataSources.

                Comment


                  #9
                  From any other DataSource can we export other than RestDataSource and XJSONDDataSource.

                  Comment


                    #10
                    Right.

                    exportData() works for DataSources based on .ds.xml files, as previously stated and as explained in the docs.

                    Comment


                      #11
                      Can you please guide me how to get ds.xml from datasource.

                      Thanks in Advance.

                      Comment


                        #12
                        Sorry, that does not make sense. A server-side DataSource is defined by a .ds.xml file. You do not get a .ds.xml from a DataSource, you define a DataSource via a .ds.xml file.

                        For more information, please re-read the QuickStart Guide as well as the documentation for exportData() and exportClientData().

                        Comment

                        Working...
                        X