Results 1 to 8 of 8

Thread: Grid Panel Index of First and Last visible row

  1. #1
    Ext JS Premium Member
    Join Date
    May 2008
    Posts
    44

    Default Answered: Grid Panel Index of First and Last visible row

    I need to display a toolbar at the bottom of the grid which says Displaying X to Y of Total number of records. Can somebody please tell me how to find out X - the first visible row on the screen and Y - the last visible row on the screen.

    Thanks for your help,
    Mandeep

  2. http://docs.sencha.com/ext-js/4-1/#!...isibleRowIndex

    For the last you'll probably have to do some calculation, which should be fairly easy if your rows are fixed hieight:

    firstRow + (view area height / row height)

  3. #2
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    347

    Default

    Why don't you use Ext.toolbar.Paging? However, if you still want to build your seft, here is the code from Paging toolbar:
    Code:
        getPageData : function(){
            var store = this.store,
                totalCount = store.getTotalCount();
    
    
            return {
                total : totalCount,
                currentPage : store.currentPage,
                pageCount: Math.ceil(totalCount / store.pageSize),
                fromRecord: ((store.currentPage - 1) * store.pageSize) + 1,
                toRecord: Math.min(store.currentPage * store.pageSize, totalCount)
            };
        },

  4. #3
    Ext JS Premium Member
    Join Date
    May 2008
    Posts
    44

    Default

    Thanks for your response. Sorry I forgot to mention that I am using Infinite Grid, so I don't have any concept of PageSize.

  5. #4
    Ext JS Premium Member
    Join Date
    Nov 2009
    Location
    St Louis,MO
    Posts
    267
    Answers
    20

    Default

    http://docs.sencha.com/ext-js/4-1/#!...isibleRowIndex

    For the last you'll probably have to do some calculation, which should be fairly easy if your rows are fixed hieight:

    firstRow + (view area height / row height)

  6. #5
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505

    Default

    I did the following in order to not have to rely on static rowsizes:
    I just added the following listener to the infinite grid example in the 4.1.1 SDK

    Code:
    listeners: {
        viewready: function(grid) {
            grid.view.el.on({
                scroll: function () {
                    var vTop = grid.view.el.getTop()
                        , vBottom = grid.view.el.getBottom()
                        , top, bottom;
    
    
                    Ext.each(grid.view.getNodes(), function (node) {
                        if (!top && Ext.fly(node).getBottom() > vTop) {
                            top = grid.view.getRecord(node).index;
                        }
                        if (Ext.fly(node).getTop() < vBottom) {
                            bottom = grid.view.getRecord(node).index;
                        }
                    });
    
    
                    console.log(top + 1);
                    console.log(bottom + 1)
                }
                , buffer: 200
            });
        }
    }

  7. #6
    Ext JS Premium Member
    Join Date
    May 2008
    Posts
    44

    Default getLastVisibleRowIndex()

    Found out that Ext.grid.PagingScroller also has a function getLastVisibleRowIndex() also to get the last row. Its not specified in the API but its there in the class. So I am going to use getLastVisibleRowIndex() and getFirstVisibleRowIndex() for my toolbar. For some reason getFirstVisibleRowIndex() is returning two less than the actual starting row index. I can add 2 but would be nice to know why?

    Thanks to both of you for suggesting good solutions.

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

    Default

    In the upcoming 4.2, the new BufferedRenderer class has methods to find the first visible row and lastVisibleRow.

    In 4.1, this is the PagingScroller which has these methods.

    You could copy/paste/adapt the code from there.

  9. #8
    Sencha Premium Member
    Join Date
    Apr 2012
    Location
    India
    Posts
    33

    Default How to set Default visible columns for ExtJs Grid panel

    Hi,

    I have requirement like setting the default visible columns, For example, I have 42 columns in Grid panel, while rendering Grid panel, it is showing from the first column index. but it should show from 10th column index lesser that 10 columns should be visible after moving the horizontal scroll bar. Is there any solution to resolve this issue?, If there is Please help me to resolve this issue.


    Thanks in Advance

Posting Permissions

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