Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: [SOLVED] Array grid example from docs, scrolling to last row of grid not working!

  1. #1
    Ext User violinista's Avatar
    Join Date
    Apr 2007
    Location
    Serbia
    Posts
    293

    Default [SOLVED] Array grid example from docs, scrolling to last row of grid not working!

    Hello all,

    I have a need for making grid scrolling to bottom, after loading it. As usual, i try it first on provided examples (which are great ones, BTW), and was surprised with some (for me) strange issue. I edited the simplest, array.js:

    PHP Code:
    .
    .
    .
    grid.render();

    grid.getSelectionModel().selectLastRow();  //works as in docs, but not as intended- only selects last row 
    grid.getView().focusRow(15);  //doesnt work, throws an error.
    grid.scrollTo(15);  //doesnt work, throws an error 
    I have tried both 1.0.0 and 1.0.1 versions of ExtJs and it was always the case. Where am I doing wrong? I was searching all morning through examples, docs and forum, and found these focusRow(), selectLastRow(), and scrollTo() methods, but they does not work.

    Thanks in advance!

  2. #2
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    "throws an error" does not tell any potential helper anything.

    Which bit of the documentation that you searched mentions a "scrollTo" method of the Grid?

    This:
    Code:
    grid.getView().focusRow(n);
    Does in fact work where "grid" references a valid Grid object. It will scroll it into view.

    Then:
    Code:
    grid.getSelectionModel().selectRow(n);
    will select that row.

    You can test these without creating your own test page. Just set a breakpoint in the Array Grid example after the grid has been created, then switch to the console and type

    Code:
    window.grid = grid
    This creates a global variable called "grid" which you can use later...

    Then switch back to the debug tab, and click "continue". After the grid has been created, go to the console, and you can experiment with these calls using the global "grid" variable, and see that they work.

  3. #3
    Ext User violinista's Avatar
    Join Date
    Apr 2007
    Location
    Serbia
    Posts
    293

    Default

    In array example, which I am using, grid is defined in standard fashion:

    PHP Code:
    var grid = new Ext.grid.Grid('grid-example', {
                
    dsds,
                
    cmcolModel,

            }); 
    After that, it is rendered:

    PHP Code:
    grid.render(); 
    Displayed correctly. When I try to do:

    PHP Code:
    grid.getView().focusRow(15); 
    it throws an error: "_27.rows[_24] has no properties" in Ext-all.js.

    Thanks!

  4. #4
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    Don't forget it's asynchronous. There might not be a 15th row if you are running that code right after the render call.

    This stuff works consistently, I don't understand what the problem is!

  5. #5
    Ext User violinista's Avatar
    Join Date
    Apr 2007
    Location
    Serbia
    Posts
    293

    Default

    That means I have to wait a bit before doing focusRow()?

  6. #6
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    Well, the usual.... hook the Store's load event with a single:true handler.

  7. #7
    Ext User violinista's Avatar
    Join Date
    Apr 2007
    Location
    Serbia
    Posts
    293

    Default

    so, after grid.render() I typed:

    PHP Code:
            grid.getDataSource().on("load", function() {
                
    grid.getView().focusRow(5);
            },
            {
                
    single:true
            
    }); 
    ...and the 5th row is not focused. Is there some other way to scroll/focus the [5th |Nth | last] row of datagrid? Actually, I need to scroll to last row of the dataGrid after dataStore is loaded.

    Thanks!

  8. #8
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    After the grid render. Would the Store already be loaded then? Have you already called load()?

    focusRow just scrolls it into view SelectionModel.selectRow() selects

    You're using the on function wrong: http://extjs.com/deploy/ext/docs/out...ml#addListener

  9. #9
    Ext User violinista's Avatar
    Join Date
    Apr 2007
    Location
    Serbia
    Posts
    293

    Default

    The complete code is:

    PHP Code:
    var ds = new Ext.data.Store({ .... });
    ds.load();

    var 
    grid = new Ext.grid.Grid( .... );

    grid.render();

            
    grid.getDataSource().on({"load": {
                
    fn:function() {
                    
    grid.getView().focusRow(15);
                },
                
    options: {
                    
    single:true
                
    }}}); 
    ...and 15th row is neither scrolledIntoView, nor FireBug throws error message-it seems syntax is OK, but no desired action at all.

  10. #10
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    Well the grid is loaded, so it's not going to fier the load event again!

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •