Announcement

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

    how to specify datasource for dynamic grid

    We are building a dynamic grid where the column in the grid is dynamic. Our application allows user to pick the columns (we call data points) that the user is interested, and build the grid based on user’s selection. There could be a million columns (data points) that the user can pick from. Normally user picks a few data point (less than 20) and run the report. Each datapoint can be of different type: string, numeric, or date.


    How do I specify the fields in the datasource? Can I set the fields for the data source in the server fetch method? That will be the ideal place, but I don’t know what needs to be done

    The following is the static data source where I don’t specify the field. I don’t get any data back using this datasource because the fields are not specified:

    <DataSource ID="FSReportDS" titleField="description" serverType="generic" dataFormat="iscServer">
    <fields>
    </fields>
    <serverObject lookupStyle="new" className="com.insx.isomorphic.ds.FSReportDS" />

    We are using SmartClient_80_Pro

    Thanks in advance

    #2
    The most convenient API is DataSource.addDynamicDSGenerator(). So basically you'd make up an arbitrary ID that represents the set of dynamically chosen fields, and install a DynamicDSGenerator that will return the DataSource definition when that ID is asked for.

    Comment


      #3
      Thanks for the suggestion. Will the dynamic datasource support pagination? We need to support pagination and export for the grid.

      Comment


        #4
        Yes it's indistinguishable from a normal DataSource created from a .DS.XML file.

        Comment


          #5
          Thanks for the response. I tried the approach and have some questions.

          How do I load the datasource at the client side? I'm using the following to load the datasource, where "FSReportDS" is the prefix:
          <isomorphic:loadDS ID="FSReportDS"/

          This line does invoke the getDataSource, but the dsRequest passed into the getDataSource is null. I need the dsRequest to get the user session information in order to create the datasource.

          How do I pass in a valid dsRequest when loading the datasource at the client side?

          My display grid page at the client side flows as the following:
          1. load the datasource
          2. create the grid using the datasource
          3. call fetchData to populate the grid

          Comment


            #6
            I found this thread which is quite similar to what I'm trying to do:
            http://forums.smartclient.com/showthread.php?t=15927&highlight=dynamic+datasource

            DataSource.addDynamicDSGenerator() is not recommended in this case because the datasource is also user specify. We need a different datasource for each user, each report.

            I will try the fromXML approach described in the example.

            Comment


              #7
              Both could be used, but yeah, fromXML() is a reasonable way to do a user-specific DataSource.

              Comment


                #8
                I used the fromXML method, created a dynamic datasource, but somehow, the sysmte give me this error:
                Can’t find dataSource: FSReportDS – please make sure that you have a FSReportDS.ds.xml file for it in [webRoot]/shared/ds

                If I put a static file (see attached FSReportDS.ds.xml) there, it works fine.
                See attached test.jsp and test.html. The test.html is generated from test.jsp

                the alert(FSReportDS) statement after the datasource generation actually print out an valid object (it prints out [DATASOURCE ID: FSReportDS]) , not sure why the fetchData statement couldn't find the datasource.

                Thanks in advance.
                Attached Files

                Comment


                  #9
                  Your fromXML() call here is just going to get this DataSource delivered to the browser, there is no record of it on the server. You still to add a subclass of the IDACall servlet to dynamically create the DataSource and call execute() on it with DSRequests. Take a closer look at the samples in the thread you referenced.

                  Comment


                    #10
                    Thank you for the quick response. Do you mean to do the following:
                    Write a class that inherit from IDACall, override the handDSRequest method. Inside the handleDSRequest, look for the datasource name in the dsRequest, if it is requesting my datasource, I will create the datasource using the same xml (fromXML) as the one use for client, call the execute on the generated datasource to get the response.

                    To tell the system to use my implementation of the IDACall rather than the default, do you mean to change the server-class in the web.xml:
                    <servlet>
                    <servlet-name>IDACall</servlet-name>
                    <servlet-class>com.isomorphic.servlet.IDACall</servlet-class>
                    </servlet>

                    This will affect the whole application, and I’m a little hesitate on that.

                    I don’t see any code sample in that thread. Could you send me some sample server side implementation? That will be very helpful

                    Comment


                      #11
                      You've got the right idea, there's sample code for processing requests right in the IDACall docs. All you need to do to avoid affecting any built-in behaviors is call super() for all requests that aren't going to your special dynamically-generated DataSource.

                      Comment


                        #12
                        I've made a subclass of IDACall called InsIDACall, but I'm getting the following exception. Not sure what's missing.

                        === 2011-06-22 12:40:51,094 [sor2] ERROR InsIDACall - Error executing operation: FSReportDS_fetch
                        java.lang.Exception: Operation type 'fetch' not supported by this DataSource (FSReportDS)
                        at com.isomorphic.datasource.DataSource.notSupported(DataSource.java:1874)
                        at com.isomorphic.datasource.DataSource.executeFetch(DataSource.java:1814)
                        at com.isomorphic.datasource.DataSource.execute(DataSource.java:1048)
                        at com.insx.isomorphic.ds.InsIDACall.handleDSRequest(InsIDACall.java:51)
                        at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:130)
                        at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:95)
                        at com.isomorphic.servlet.IDACall.doPost(IDACall.java:54)
                        at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
                        at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
                        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)

                        See attached files, InsIDACall is the subclass, and the FSReportDS.java is the server object to carry out the fetch operation.
                        Attached Files

                        Comment


                          #13
                          OK, your IDACall code is fine, now, whatever XML you're returning to fromXML isn't valid in some way - it doesn't provide a way to execute the "fetch" operation, as the log says.

                          Comment


                            #14
                            Thanks for the suggestions.

                            The serverObject element is dropped after the call to fromXML and JSTranslater.get().toJS(ds); Not sure if there is an bug in the two API.

                            Here is the XML string for the data source where you can see serverObject element is in it:
                            <?xml version="1.0" encoding="UTF-8"?>

                            <DataSource ID="FSReportDS" titleField="description" serverType="generic" dataFormat="iscServer"><operationBindings><binding operationType="fetch" serverMethod="fetchData"><serverObject lookupStyle="new" className="com.insx.isomorphic.ds.FSReportDS" /></binding></operationBindings><fields><field title="Code" name="c0" type="text" /><field title="Company" name="c1" type="text" /><field title="YQ_Flag" name="c2" type="integer" formatCellValue="isc.Format.toUSString(value)" /><field title="Group code {2010}" name="c3" type="text" /><field type="text" name="company_code" hidden="true" /><field type="text" name="company_code_dis" hidden="true" /><field type="text" name="group_code" hidden="true" /><field type="text" name="ins_type" hidden="true" /></fields></DataSource>

                            After passing the xml string to the following two api calls, the serverObject element is dropped:
                            DataSource ds = DataSource.fromXML(docStr);
                            String dsStr = JSTranslater.get().toJS(ds);


                            Here is the generated javascript where the serverObject element for binding is missing:
                            isc.DataSource.create({
                            titleField:"description",
                            serverType:"generic",
                            dataFormat:"iscServer",
                            fields:[
                            {
                            name:"c0",
                            title:"Code",
                            type:"text"
                            },
                            {
                            name:"c1",
                            title:"Company",
                            type:"text"
                            },
                            {
                            formatCellValue:"isc.Format.toUSString(value)",
                            name:"c2",
                            title:"YQ_Flag",
                            type:"integer"
                            },
                            {
                            name:"c3",
                            title:"Group code {2010}",
                            type:"text"
                            },
                            {
                            hidden:true,
                            name:"company_code",
                            type:"text"
                            },
                            {
                            hidden:true,
                            name:"company_code_dis",
                            type:"text"
                            },
                            {
                            hidden:true,
                            name:"group_code",
                            type:"text"
                            },
                            {
                            hidden:true,
                            name:"ins_type",
                            type:"text"
                            }
                            ],
                            operationBindings:[
                            {
                            serverMethod:"fetchData",
                            operationType:"fetch"
                            }
                            ],
                            ID:"FSReportDS"
                            })

                            Comment


                              #15
                              See attached test2.jsp, it uses the SmartClient distributed datasource (
                              SmartClient_80_Pro/smartclientSDK/examples/shared/ds/worldDSExportCustom.ds.xml) as an example and prove that after DataSource.fromXML call and the JSTranslater.get().toJS call, the serverObject element is dropped.
                              Attached Files

                              Comment

                              Working...
                              X