Announcement

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

    Live Grid support dynamic fetching of data from server?

    Hi,

    This might be a question for the javascript SmartClient library forum...

    I'm exploring the Live Grid example to see if it can scale up to meet our needs. We could have 5,000 rows of data in the result set we need to view in a grid.

    Obviously we don't want to load all 5,000 rows into the grid at once. From the LiveGrid example, I see the ListGrid supports lazy-rendering so only the data needed to fill the viewable area is rendered. That's good - but that only solves part of the problem.

    It looks like the datasource returns the entire file at once. What I need is a dynamic data source where only N rows are fetched at a time and then as the user scrolls down, more rows are fetched and then rendered as needed.

    Does SmartClient support this?

    The current grid we are using (the dhtmlxgrid from www.dhtmlx.com) does support lazy loading and lazy rendering. But I'd prefer to use the SmartClient list grid if it can do the same.

    thanks,
    Tom

    #2
    Yes, the SmartClient / SmartGWT "LiveGrid" behavior supports data paging. Take a look at the docs for RestDataSource and particularly note the startRow/endRow/totalsRows parameters being passed - that's the basis of the paging protocol, and it works with any server and wire format.

    What you're seeing in the SmartGWT showcase is that, since it has no server code, the complete datasets are being loaded by clientOnly:true DataSources which then simulate server requests when components ask for data (extremely useful for prototyping).

    See also the ResultSet docs for a more complete picture of how this whole subsystem works. The ResultSet class doesn't appear in the SmartGWT documentation yet, but it is in there and docs will appear in the nightlies soon.

    Comment


      #3
      That's good news.

      I looked into it and found it is really very simple.

      Code:
      RestDataSource testDS = new RestDataSource();
      testDS.setFetchDataURL(GWT.getModuleBaseURL() + "/GetGridData.xml");
      
      ListGrid listGrid = new ListGrid();
      listGrid.setWidth100();
      listGrid.setHeight100();
      
      listGrid.setShowAllRecords(false);
      listGrid.setDataSource(testDS);
      listGrid.setDataPageSize(45);
      
      // ... set ListGridFields, etc.
      The server side is simply a servlet handler that gets the following request parameters:

      _dataSource
      _operationType
      _startRow
      _endRow

      And returns XML like this:
      Code:
      <response>
        <status>0</status>
        <startRow>X</startRow>
        <endRow>Y</endRow>
        <totalRows>5000</totalRows>
        <data>
           <record>
               <column1Name>Column 1 data</column1Name>
               <column2Name>Column 2 data</column2Name>
           </record>
        </data>
      </response>
      The one problem I'm having though is I'm getting a weird exception in the GWT hosted mode - although it works perfectly if I deploy it as a full webapp and view it with Firefox or IE. It's probably a question for Sanjiv since it seems to be GWT-specific.

      The exception is:
      Code:
      java.lang.ClassCastException
      	at java.lang.Class.cast(Unknown Source)
      	at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:125)
      	at com.google.gwt.dev.shell.ie.SwtOleGlue.convertVariantsToObjects(SwtOleGlue.java:57)
      	at com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:119)
      	at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:155)
      	at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
      	at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
      	at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
      	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
      	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
      	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
      	at com.google.gwt.dev.GWTShell.pumpEventLoop(GWTShell.java:720)
      	at com.google.gwt.dev.GWTShell.run(GWTShell.java:593)
      	at com.google.gwt.dev.GWTShell.main(GWTShell.java:357)
      Uncaught JavaScript exception [java.lang.ClassCastException: null
      	at java.lang.Class.cast(Unknown Source)
      	at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:125)
      	at com.google.gwt.dev.shell.ie.SwtOleGlue.convertVariantsToObjects(SwtOleGlue.java:57)
      	at com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:119)
      	at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:155)
      	at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
      	at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
      	at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
      	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
      	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
      	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
      	at com.google.gwt.dev.GWTShell.pumpEventLoop(GWTShell.java:720)
      	at com.google.gwt.dev.GWTShell.run(GWTShell.java:593)
      	at com.google.gwt.dev.GWTShell.main(GWTShell.java:357)] in http://localhost:8888/com.rg.gwt.test.Test/hosted.html?com_rg_gwt_test_Test, line 16
      Any ideas?

      thanks,
      Tom

      Comment


        #4
        I think the problem is in <totalRows>5000</ totalRows>, the value has to be <totalRows>1</ totalRows> Try it.

        Comment


          #5
          <totalRows>5000</ totalRows> is correct as it is used to indicate to the client how many rows exist on the server.

          Tom, I'll look into the hosted mode specific exception.

          Thanks,
          Sanjiv

          Comment


            #6
            I have the same problem.. At first, I thought something wrong is with my code as rendering of new fetched data did not worked in hosted browser, but later when I tried compiled java script code in real browser it worked perfectly..
            I am getting the same Exception in hosted mode.

            Comment


              #7
              how can i add paging

              Hello,

              how can i add paging in grid with smartgwt



              Please reaply me ASAP

              thanks
              rahul


              Originally posted by Isomorphic
              Yes, the SmartClient / SmartGWT "LiveGrid" behavior supports data paging. Take a look at the docs for RestDataSource and particularly note the startRow/endRow/totalsRows parameters being passed - that's the basis of the paging protocol, and it works with any server and wire format.

              What you're seeing in the SmartGWT showcase is that, since it has no server code, the complete datasets are being loaded by clientOnly:true DataSources which then simulate server requests when components ask for data (extremely useful for prototyping).

              See also the ResultSet docs for a more complete picture of how this whole subsystem works. The ResultSet class doesn't appear in the SmartGWT documentation yet, but it is in there and docs will appear in the nightlies soon.

              Comment


                #8
                Hi Rahul - it seems that the reply you just quoted contains the answer you're looking for?

                Comment


                  #9
                  Rahul - we've seen your message duplicated on several unrelated threads.

                  We're deleting these messages as duplicates.
                  If you still don't understand how to get paging working, please explain exactly what problems you're having here.

                  Repeating the original question across multiple threads which are intended to discuss different issues is not going to help get your question answered, and is frustrating for other users who are following the discussions within those threads.
                  If the answer we've given is unclear - please explain what it is you don't understand rather than attempting to get a different response by hijacking other threads.

                  Thanks
                  Isomorphic Software

                  Comment


                    #10
                    sorry for duplicated message

                    Hello,


                    Sorry for that but the messages was send by mistake from my side


                    my code is look like this and i want to add paging in this code.but i am not be able to understand how can i implement this feature can you send me some code example for paging.


                    Code:-

                    final ListGrid countryGrid = new ListGrid();
                    countryGrid.setWidth(800);
                    countryGrid.setHeight(750);
                    countryGrid.setAlternateRecordStyles(true);
                    countryGrid.setShowFilterEditor(true);
                    countryGrid.setFilterOnKeypress(true);
                    countryGrid.setDataSource(WorldXmlDS.getInstance() );
                    countryGrid.setAutoFetchData(true);

                    ListGridField countryCodeField = new ListGridField("JB_job_number", "Job_No", 50);
                    ListGridField nameField = new ListGridField("JAT_prio", "priority");
                    ListGridField capitalField = new ListGridField("JB_name", "job_name");
                    ListGridField continentField = new ListGridField("JB_owner", "owner");
                    ListGridField stateField = new ListGridField("state", "State");
                    ListGridField stimeField = new ListGridField("JAT_start_time", "Time");
                    ListGridField quetField = new ListGridField("queue_name", "Qname");
                    ListGridField slotetField = new ListGridField("slots", "Slote");

                    countryGrid.setFields(countryCodeField, nameField, capitalField, continentField, stateField, stimeField, quetField, slotetField );

                    return countryGrid;

                    Please send me some code example.

                    reply me ASAP

                    Thanks a lot

                    rahul

                    Comment


                      #11
                      You are a real mystery :)

                      The very first time you posted you were referred to the docs for RestDataSource and these running examples. You obviously still have not looked at either.

                      Please do not post again until you've reviewed the docs and example in great detail, otherwise, your future posts are just going to be deleted to prevent community member's time from being wasted.

                      Comment


                        #12
                        Tom,
                        If you run against SVN you should no longer get the hosted mode specific ClassCastException when lazy loading records. Can you please verify and confirm?

                        Thanks,
                        Sanjiv

                        Comment


                          #13
                          I can confirm that lazy loading now works in hosted mode using the latest from SVN.

                          Comment

                          Working...
                          X