Announcement

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

    LiveGrid and dataPageSize property

    Just started to play with SmartGWT (1.0b1) and experienced strange problem. Example code that creates grid:
    Code:
           final int COLUMN_COUNT = 25;
           final int ROW_COUNT = 1000;
    
            ListGrid grid = new ListGrid();
            grid.setWidth(600);
            grid.setHeight(400);
            // grid.setDataPageSize(ROW_COUNT);
    
            ListGridField[] gridFields = new ListGridField[COLUMN_COUNT];
            for (int i = 0; i < COLUMN_COUNT; i++) {
                gridFields[i] = new ListGridField("d" + i, 50);
            }
            grid.setFields(gridFields);
    
            DataSource dataSource = new DataSource();
            dataSource.setClientOnly(true);
            DataSourceIntegerField keyField = new DataSourceIntegerField("id");
            keyField.setPrimaryKey(true);
            keyField.setHidden(true);
            dataSource.addField(keyField);
            for (int i = 0; i < COLUMN_COUNT; i++) {
                dataSource
                        .addField(new DataSourceTextField("d" + i, "#" + (i + 1)));
            }
            for (int i = 0; i < ROW_COUNT; i++) {
                ListGridRecord record = new ListGridRecord();
                record.setAttribute("id", i);
                for (int j = 0; j < COLUMN_COUNT; j++) {
                    record.setAttribute("d" + j, (i + 1) + "x" + (j + 1));
                }
                dataSource.addData(record);
            }
            grid.setDataSource(dataSource);
    
            grid.setAutoFetchData(true);
    
            RootPanel.get().add(grid);
    While grid.setDataPageSize(ROW_COUNT) is commented the content of grid is partially wrong, seems as some rows repeated and some missing: there are rows (hereinafter I mention row by first column) 1x1..76x1, then it starts again from 2x1 and finishes on 724x1. Note that default value for dataPageSize is documented as 75.

    Is there something wrong with my code?

    #2
    Tried the latest build from SVN - problem is still there. Also tried to download data from server using RestDataSource - paging code (actually it is in ResultSet class, it fetches row ranges from DataSource by demand) in ListGrid seems buggy, I got number of blank rows in table start and also some rows missing in the middle of the table. Probably it is core SmartClient bug.

    Comment


      #3
      No, there is definitely not a "core SmartClient bug" involving missing rows in paging. Try any of the countless samples, which work with a variety of different DataSources. This has been deployed in major applications for 8 years (yes really).

      The problem with your attempt is that you should be calling setTestData(). addData() is an asynchronous operation and the various adds are in effect happening concurrently with the fetch. This won't cause blank rows if your code is correct, but it will scramble the order.

      Comment


        #4
        Can you try running this is web mode (compile and open in browser)? There is a known SmartGWT issue of virtual scrolling in hosted mode that I'm hoping to get to this week.

        Sanjiv

        Comment


          #5
          "The problem with your attempt is that you should be calling setTestData(). addData() is an asynchronous operation and the various adds are in effect happening concurrently with the fetch"

          Yes, I'm sure it was the reason why "client only" code behaves so strange.

          But with real remote access it still works not proper way. Would show some dirty example.

          Client code (for module test.smartgwt.TestSmartGWT, deployed to "www" folder in .war root):
          Code:
          		ListGrid grid = new ListGrid();
          		grid.setWidth(600);
          		grid.setHeight(400);
          
          		ListGridField[] gridFields = new ListGridField[25];
          		for (int i = 0; i < gridFields.length; i++) {
          			gridFields[i] = new ListGridField("d" + i, 50);
          		}
          		grid.setFields(gridFields);
          
          		RestDataSource dataSource = new RestDataSource();
          		dataSource.setFetchDataURL(GWT.getModuleBaseURL().replace(
          				"www/test.smartgwt.TestSmartGWT/", "rowProvider"));
          		DataSourceIntegerField keyField = new DataSourceIntegerField("id");
          		keyField.setPrimaryKey(true);
          		keyField.setHidden(true);
          		dataSource.addField(keyField);
          		for (int i = 0; i < gridFields.length; i++) {
          			dataSource
          					.addField(new DataSourceTextField("d" + i, "#" + (i + 1)));
          		}
          		grid.setDataSource(dataSource);
          
          		grid.setAutoFetchData(true);
          
          		RootPanel.get().add(grid);
          Servlet code (servlet mapped to "/rowProvider" path in web.xml):
          Code:
              @Override
              protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                      throws ServletException, IOException {
                  doService(req, resp);
              }
          
              @Override
              protected void doPost(HttpServletRequest req, HttpServletResponse resp)
                      throws ServletException, IOException {
                  doService(req, resp);
              }
          
              private void doService(HttpServletRequest req, HttpServletResponse resp)
                      throws ServletException, IOException {
                  resp.setContentType("text/xml");
          
                  String startRowParam = req.getParameter("_startRow");
                  int startRow = startRowParam != null ? Integer.parseInt(startRowParam)
                          : 0;
          
                  String endRowParam = req.getParameter("_endRow");
                  int endRow = endRowParam != null ? Integer.parseInt(endRowParam) : 999;
                  if (endRow > 999) {
                      endRow = 999;
                  }
          
                  PrintWriter writer = resp.getWriter();
                  writer.append("<response>");
                  writer.append("<status>0</status>");
                  writer.append("<data>");
                  writer.append("<totalRows>");
                  writer.append("" + 1000);
                  writer.append("</totalRows>");
                  if (startRow <= endRow) {
                      writer.append("<startRow>");
                      writer.append("" + startRow);
                      writer.append("</startRow>");
                      writer.append("<endRow>");
                      writer.append("" + endRow);
                      writer.append("</endRow>");
                      for (int i = startRow; i <= endRow; i++) {
                          writer.append("<record>");
                          writer.append("<id>");
                          writer.append("" + i);
                          writer.append("</id>");
                          for (int j = 0; j < 25; j++) {
                              String tag = "d" + j;
                              writer.append("<" + tag + ">");
                              writer.append((i + 1) + "x" + (j + 1));
                              writer.append("</" + tag + ">");
                          }
                          writer.append("</record>");
                      }
                  }
                  writer.append("</data>");
                  writer.append("</response>");
          
                  log("Fetched rows: " + startRow + "-" + endRow);
              }
          Example is running in "browser" mode (means not host GWT mode) on Jetty servlet container.

          Result is: table appears with 3 empty rows on start, then 1x1, 2x1 rows appear etc. and row 997x1 is in the end of the table. Also randomly I got holes (not loaded rows) in the middle of the table, it looks like: row 832x1 exists then 3 empty rows and then 836x1 etc.

          Is there anything wrong with my example now?
          Last edited by dmukhin; 11 Jan 2009, 05:07.

          Comment


            #6
            Ok, I solved the problem - in server response <totalRows>, <startRow> and <endRow> should appear under <response> not <data> element.

            Comment

            Working...
            X