Announcement

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

    exportClientData and clientExport operationBinding: exportFilename ignored ?

    SmartClient Version: v12.1p_2020-09-18/Enterprise Deployment (built 2020-09-18)
    Chrome, FF on OSX

    Hello, I'm using grid.exportClientData, with exportAs:"xls", and I need to access the Workbook to set all cells to text format (instead of the default which is general):

    Code:
            <operationBinding operationType="clientExport" operationId="testExport">
                <script language="groovy">
                    DSResponse dsResponse = dsRequest.execute();
                    org.apache.poi.ss.usermodel.Workbook workbook = (org.apache.poi.ss.usermodel.Workbook) dsResponse.getExportObject(dsRequest);
                    org.apache.poi.ss.usermodel.Sheet sheet = workbook.getSheetAt(0);
                    org.apache.poi.ss.usermodel.DataFormat fmt = workbook.createDataFormat();
                    org.apache.poi.ss.usermodel.CellStyle textStyle = workbook.createCellStyle();
                    short format = fmt.getFormat("text");
                    textStyle.setDataFormat(format);
                    for (org.apache.poi.ss.usermodel.Row row : sheet) {
                        for (org.apache.poi.ss.usermodel.Cell cell : row) {
                            cell.setCellStyle(textStyle);
                        }
                    }
                    dsResponse.setExportObject(workbook);
                    return dsResponse;
                </script>
    This is working, but the browser downloads a 'IDACall' file (without extension), which is the correct excel file.
    Also if I use exportFilename, ie:
    Code:
    gestioneDipendentiGrid.exportClientData({exportAs:"xls", operationId:"testExport", exportFilename:"test.xls"})
    the name isn't used.
    Is it expected? Do I have to make a custom response?
    Last edited by claudiobosticco; 18th Sep 2020, 08:41.

    #2
    SmartClient Version: v12.1p_2020-09-23/Enterprise Deployment (built 2020-09-23)
    Chrome on OSX

    Hello, I managed to put together a test case in the showcase.
    Please modify the #enterNewRows sample like this:

    Code:
    isc.ListGrid.create({
        ID: "countryList",
        width:500, height:224, alternateRecordStyles:true,
        // use server-side dataSource so edits are retained across page transitions
        dataSource: countryDS,
        // display a subset of fields from the datasource
        fields:[
            {name:"countryName"},
            {name:"continent"},
            {name:"member_g8"},
            {name:"population"},
            {name:"independence"}
        ],
        autoFetchData: true,
        canEdit: true,
        editEvent: "click",
        listEndEditAction: "next"
    })
    
    isc.IButton.create({
        top:250,
        title:"Export",
        click:'countryList.exportClientData({exportAs:"xls", operationId:"testExport", exportFilename:"test.xls"})'
    });
    Then modify its dataSource (countrySQLDS.ds.xml) like this:

    Code:
    <DataSource
        ID="countryDS"
        serverType="sql"
        recordName="country"
        testFileName="/examples/shared/ds/test_data/country.data.xml"
    >
        <fields>
            <field name="pk"            type="integer"    hidden="true"            primaryKey="true" />
            <field name="countryCode"   type="text"       title="Code"             required="true"   />
            <field name="countryName"   type="text"       title="Country"          required="true"   />
            <field name="capital"       type="text"       title="Capital"          />
            <field name="government"    type="text"       title="Government"       length="500"      />
            <field name="continent"     type="text"       title="Continent"        >
                <valueMap>
                    <value>Europe</value>
                    <value>Asia</value>
                    <value>North America</value>
                    <value>Australia/Oceania</value>
                    <value>South America</value>
                    <value>Africa</value>
                </valueMap>
            </field>
            <field name="member_g8"     type="boolean"    title="G8"               />
            <field name="independence"  type="date"       title="Nationhood"          />
            <field name="area"          type="float"      title="Area (km&amp;sup2;)" format=",0" />
            <field name="population"    type="integer"    title="Population"          format=",0" />
            <field name="gdp"           type="float"      title="GDP"                 format="&#x00A4;,0.0M" />
            <field name="article"       type="link"       title="Infooo"                detail="true"    />
        </fields>
        <operationBindings>
            <operationBinding operationType="clientExport" operationId="testExport">
                <script language="groovy">
                    DSResponse dsResponse = dsRequest.execute();
                    org.apache.poi.ss.usermodel.Workbook workbook = (org.apache.poi.ss.usermodel.Workbook) dsResponse.getExportObject(dsRequest);
                    org.apache.poi.ss.usermodel.Sheet sheet = workbook.getSheetAt(0);
                    org.apache.poi.ss.usermodel.DataFormat fmt = workbook.createDataFormat();
                    org.apache.poi.ss.usermodel.CellStyle textStyle = workbook.createCellStyle();
                    short format = fmt.getFormat("text");
                    textStyle.setDataFormat(format);
                    for (org.apache.poi.ss.usermodel.Row row : sheet) {
                        for (org.apache.poi.ss.usermodel.Cell cell : row) {
                            cell.setCellStyle(textStyle);
                        }
                    }
                    dsResponse.setExportObject(workbook);
                    return dsResponse;
                </script>
            </operationBinding>
        </operationBindings>
    </DataSource>
    Then hit the 'Export' button and a IDACall file will be downloaded.

    Comment

    Working...
    X