Announcement

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

    ListGrid (make record visible)

    The more I use smartGWT the more I like it.

    Another question please...
    I have a ListGrid that I would like to scroll it so a specific Record to became visible.
    How could I do this?

    Thank you again.
    Yorgos

    #2
    I have added a couple of methods in SVN for this.

    ListGrid.scrollBodyTo(left, top)

    This method allows you to control the grids horizontal and vertical scroll position.

    I have also added a convenience method that allows you to scroll to a specific record.

    ListGrid.scrollToRow(rowNum)

    which essentially does

    Code:
    public void scrollToRow(int rowNum) {
        int cellHeight = getCellHeight();
        scrollBodyTo(null, (rowNum - 1) * cellHeight);
    }
    Sanjiv

    Comment


      #3
      It seems to me that there is a problem with the scrollToRow(n)

      I call:
      int n = getRecordIndex (r);
      scrollToRow(n);

      (while the record is the last record in the List)
      and it scrolls up to the one before the last (the last record remain invisible).

      I try:
      int n = getRecordIndex (r);
      scrollToRow(n+1);
      and the result is the same

      (it doesn't make visible the last record)

      Comment


        #4
        Dear Sjivan,

        It seems to me a bug. Methods for scrolling ( ListGrid.scroll* ) are no worked in IE 6, IE 7 and Google Chrome, at all. Only worked in GWT Shell.

        smartgwt-1.0b2
        Last edited by vkolotov; 11 Mar 2009, 06:45.

        Comment


          #5
          The scrollToRow() convenience method works on a ListGrid. scrollTo() etc would not be expected to do anything to the ListGrid because its the "body" subelement that actually scrolls.

          Comment


            #6
            Thanks for reply,

            but method ListGrid.scrolToRow doesn't work too (in IE 6 or IE 7 or FireFox)!

            There is a test code, please try and u'll see:

            Code:
            private void showCountryGrid() {
                    final ListGrid countryGrid = new ListGrid();
                    countryGrid.setWidth(400);
                    countryGrid.setHeight(224);
                    countryGrid.setAlternateRecordStyles(true);
                    countryGrid.setShowAllRecords(false);
                    countryGrid.setDataSource(CountryDS.getInstance());
                    countryGrid.setAutoFetchData(true);
            
                    countryGrid.draw();
            
                    Button b =  new Button("Scroll");
                    b.setTop(400);
                    b.setLeft(100);
                    b.setWidth(100);
                    b.setHeight(50);
                    b.addClickHandler( new com.smartgwt.client.widgets.events.ClickHandler() {
            
                        public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {                
                            countryGrid.scrollToRow(11);
                            Window.alert("Scrolled? - No!");
                        }
                    });
                    b.draw();
                }
            Code:
            private static class CountryDS extends DataSource {
                    // The DataSource would normally be defined external to any classes that use it.
            
                    private static CountryDS instance = null;
            
                    public static CountryDS getInstance() {
                        if (instance == null) {
                          instance = new CountryDS("countryDS_XML");
                        }
                        return instance;
                    }
            
                    public CountryDS(String id) {
                        setID(id);
                        setDataFormat(DSDataFormat.XML);
                        setRecordXPath("/List/country");
                        DataSourceField countryCodeField = new DataSourceField("countryCode", FieldType.TEXT,
                                                                               "Code");
                        DataSourceField countryNameField = new DataSourceField("countryName", FieldType.TEXT,
                                                                               "Country");
                        DataSourceField capitalField = new DataSourceField("capital", FieldType.TEXT,
                                                                           "Capital");
                        setFields(countryCodeField, countryNameField, capitalField);
                        setDataURL("country_grid.xml");
                    }
            
                }
            country_grid.xml it is xml from demo application: http://www.smartclient.com/smartgwt/...xml_datasource

            Please try it in IE 6 or IE 7 or FireFox, scroll bar doesn't move at all. But if you run it in the GWT Shell then it works.

            Comment


              #7
              A notice that may help.
              In my case, when the records are pre-exists in the ListGrid, the scrollToRow works fine.
              When I add more records and I try to scroll into the new ones it doesn't work well.
              I get the impression that it neads to show the records first and then to be able to scroll there.

              Comment


                #8
                If you add a bunch of records and immediately attempt to scroll, they may not be showing yet. You can force the new records to be drawn immediately by calling redraw() on the grid.

                Comment


                  #9
                  Dear Isomorphic,

                  I added redraw() to code sample and nothing was changed:

                  Code:
                  private void showCountryGrid() {
                          final ListGrid countryGrid = new ListGrid();
                          countryGrid.setWidth(400);
                          countryGrid.setHeight(224);
                          countryGrid.setAlternateRecordStyles(true);
                          countryGrid.setShowAllRecords(false);
                          countryGrid.setDataSource(CountryDS.getInstance());
                          countryGrid.setAutoFetchData(true);
                  
                          countryGrid.draw();
                  
                          Button b =  new Button("Scroll");
                          b.setTop(400);
                          b.setLeft(100);
                          b.setWidth(100);
                          b.setHeight(50);
                          b.addClickHandler( new com.smartgwt.client.widgets.events.ClickHandler() {
                  
                              public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
                                  countryGrid.redraw();
                                  countryGrid.scrollToRow(11);
                                  countryGrid.redraw();
                                  Window.alert("Scrolled?");
                              }
                          });
                          b.draw();
                      }
                  Please someone, provide code sample where scrolling works...
                  Last edited by vkolotov; 13 Mar 2009, 00:45.

                  Comment


                    #10
                    I solved this problem.

                    If you want to enable scrolling feature you need necessarily setup ListGridFields to a ListGrid.

                    Comment


                      #11
                      up ! The problem still exists :/

                      I cannot scroll where i want in my list grid.

                      Comment


                        #12
                        Hello, I too am having problems getting scrolling to work properly because of variable height rows.

                        Code:
                        public void scrollToRow(int rowNum) {
                            int cellHeight = getCellHeight();
                            scrollBodyTo(null, (rowNum - 1) * cellHeight);
                        }
                        This code works fine for rows that are fixed height but fails to scroll to the correct row if it is off the screen and variable row height is enabled. Is there a way to get the row height per row on this listgrid object or fix the scrollToRow() for variable height rows?

                        Comment

                        Working...
                        X