[CLOSED] PagingToolbar get PageIndex

  1. #1

    [CLOSED] PagingToolbar get PageIndex

    How do I get the PageIndex of a PagingToolbar, this was possible in older version, but I can't find the property any more?

    Last edited by fabricio.murta; Feb 14, 2020 at 12:40 AM.
  2. #2
    Hello @Jurke!

    Do you mean the current page the pager is in? Or is it something else related to the page?

    If that's the current page, you should get it off the related store instead. If you already have the paging toolbar handy in your code and don't want to go thru the trouble to get the store off its grid, you can just call paging toolbar's getStore() method. It is not private, so you are guaranteed at least a breaking change notice if this ever changes in the future.

    Once you have the store, you can then get the page by its currentPage property.

    If you really, really want to get the current page (and other page data), you can use the paging toolbar's private getPageData() method. It will return an object with a currentPage member which you can use and should match the store's.

    I am assuming you want to get the page from client-side. If you have a specific condition, it always helps to present a test case or an Ext.NET Examples's sample pointing then where exactly in the code you need to get the information. In some circumstances, from server-side, you need to "post back" the value you need, so there's little I can guess from the inquiry you currently presented.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Sorry for being unclear, in the old code I could the the current page number in code behind with this property
    PagingToolbar1.PageIndex. But that does not work any more. Is it possible to get the current page number in code behind in a DirectEvent?

  4. #4
    Hello Mikael,

    Okay, I got it. I found one example that used it, and now we can see how it does the same task. Please compare these two examples:

    - Form > Miscellaneous > Edit_Form_View in Ext.NET Examples 1
    - Form > Miscellaneous > Edit_Form_View in Ext.NET Examples 5

    Check how the DeleteClick() code-behind handler changed. I believe you may be able to apply the same change in your version.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  5. #5
    I can't implement this because in this case there is only one row, so the index of the datasource will be the same as pageIndex. I my case I have a Grid with several rows, so one page contains x rows.
    Maybe there is another way to do what I want. I want to cycle the pages automatically in the Gridpanel, this page is for showing data on a TV-screen, and if there is more than one page it should cycle them through.
    I did this manually with a timer and with the PageIndex in the old Ext. version.

  6. #6
    Hello Mikael,

    Can't you think a test case that could highlight how the data view looks like, and describe what you need to achieve in it, so we may better aid you in the issue?

    By the description you provided, it seems best rely on client-side code instead of always calling server just to advance a page in the list of entries, so instead of guesses I believe we would best switch to sample case, to allow us to provide you better advice.

    Maybe this example would be a good starting place: DataView > Basic > With_Paging

    Looking forward to your follow-up!
    Fabrício Murta
    Developer & Support Expert
  7. #7
    I manage to solve how to get the property pageIndex from the PagingToolbar, instead of getting it server side I got it from the client and then passed it to the server (DirectEvent).

    <Update OnEvent="ChangePage">
                                    <ext:Parameter Name="numberOfRows" Value="#{gpFelrapporter}.getStore().getTotalCount()" Mode="Raw" />
                                    <ext:Parameter Name="pageSize" Value="#{gpFelrapporter}.getStore().pageSize" Mode="Raw" />
                                    <ext:Parameter Name="pageIndex" Value="#{PagingToolbar1}.getPageData().currentPage" Mode="Raw" />
        public void ChangePage(object sender, DirectEventArgs e)
            int numberOfRows = GlobalFunctions.TryParseInt(e.ExtraParams["numberOfRows"].ToString());
            int pageSize = GlobalFunctions.TryParseInt(e.ExtraParams["pageSize"].ToString());
            int pageIndex = GlobalFunctions.TryParseInt(e.ExtraParams["pageIndex"].ToString());
  8. #8
    Hello agian Mikael!

    Glad you found a solution that works for you, and thanks for sharing it. Can't really say much about it, it works on your side and that's what matters, I guess.

    Something that you may want to consider is changing your pageIndex parameter to use documented and supported public interface from Sencha, that is guaranteed, worst case, to be disclosed in a breaking change if it ever changes.

    In your case you rely on private, and barely documented Ext.toolbar.Paging.getPageData() where you could just favor documented Ext.data.Store.currentPage

    That said, I believe your code where it reads:
    it should instead read
    Just like the other two extra parameters.

    Hope this helps!

    EDIT: to clarify, relying on non-documented private (or just non-documented) methods from Ext JS / Ext.NET may mean future headache as the references may be changed or even removed, renamed, without any notice.
    Last edited by fabricio.murta; Feb 12, 2020 at 4:01 PM. Reason: Clarify why undocumented/private things should not be relied upon.
  9. #9
    Great input, thanks! That row was from the old code, and was something one of you gurus (maybe Vladimir) dug up for me many years ago.
    I made the change to the code and it works great!

  10. #10
    Hello, and yes, at some point I believe this was the way to go but, through experience, and now that we have an "officially supported" way for getting the information, we should rely and migrate to it whenever possible.

    This may never change in the future. But if it does, we will at least be able to avoid hitting the wall with undisclosed changes to the API.

    I believe we are done here as well, right? I'll mark it as 'closed' but feel free to post here if you have anything to add to the thread.
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 2
    Last Post: Oct 09, 2018, 10:06 PM
  2. [CLOSED] How to get current the PageIndex?
    By blueworld in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 28, 2013, 12:04 PM
  3. [CLOSED] PagingToolbar (pageindex) not updating
    By mcfromero in forum 1.x Legacy Premium Help
    Replies: 14
    Last Post: Mar 20, 2012, 8:36 PM
  4. PagingToolbar.PageIndex doesn't work
    By YuanChien in forum 1.x Help
    Replies: 2
    Last Post: Jul 20, 2011, 8:22 AM
  5. reset gridpanel pageindex to 0 after new filter
    By javadzarrin in forum 1.x Help
    Replies: 1
    Last Post: Aug 22, 2010, 9:29 AM

Posting Permissions