PDA

View Full Version : [CLOSED] PagingToolbar get PageIndex



Jurke
Feb 07, 2020, 12:49 PM
Hi
How do I get the PageIndex of a PagingToolbar, this was possible in older version, but I can't find the property any more?

Regards
Mikael

fabricio.murta
Feb 07, 2020, 9:05 PM
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 (https://docs.sencha.com/extjs/7.1.0/classic/Ext.toolbar.Paging.html#placeholder-simple-getStore). 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 (https://docs.sencha.com/extjs/7.1.0/classic/Ext.data.Store.html#property-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 (https://docs.sencha.com/extjs/7.1.0/classic/Ext.toolbar.Paging.html#method-getPageData). 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 (https://examples5.ext.net/) 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!

Jurke
Feb 10, 2020, 8:42 AM
Hi
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?

Regards
Mikael

fabricio.murta
Feb 10, 2020, 9:12 PM
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 (https://examples1.ext.net/#/Form/Miscellaneous/Edit_Form_View/)
- Form > Miscellaneous > Edit_Form_View in Ext.NET Examples 5 (https://examples5.ext.net/#/Form/Miscellaneous/Edit_Form_View/)

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!

Jurke
Feb 11, 2020, 8:38 AM
Hi
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.

Regards
Mikael

fabricio.murta
Feb 11, 2020, 6:41 PM
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 (https://examples5.ext.net/#/DataView/Basic/With_Paging/)

Looking forward to your follow-up!

Jurke
Feb 12, 2020, 3:34 PM
Hi
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).

Client


<Update OnEvent="ChangePage">
<ExtraParams>
<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" />
</ExtraParams>
</Update>


Server


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());
}


Regards
Mikael

fabricio.murta
Feb 12, 2020, 3:58 PM
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() (https://docs.sencha.com/extjs/7.1.0/classic/Ext.toolbar.Paging.html#method-getPageData) where you could just favor documented Ext.data.Store.currentPage (https://docs.sencha.com/extjs/7.1.0/classic/Ext.data.Store.html#property-currentPage)

That said, I believe your code where it reads:


#{PagingToolbar1}.getPageData().currentPage


it should instead read


#{gpFelrapporter}.getStore().currentPage


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.

Jurke
Feb 13, 2020, 8:02 AM
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!

Regards
Mikael

fabricio.murta
Feb 14, 2020, 12:40 AM
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.