May 22, 2012, 7:30 PM
[CLOSED] Problem with paging...
Hi,
In a GridPanel of mine, I have a Store and a PagingToolbar. The Store uses a AjaxProxy. In the method that is called in the proxy I return a StoreResult.
I don't want to do a count on my tables, so everytime I set the StoreResult.Total to int.MaxValue, except when i know its the last page. this way the button 'next page' stays able to click when i know it's not the last page and disable when i do, and i hide the 'last page' button.
But when i put a number of page that don't exists (for example: 2222) and he tries to select data for that page (because it's within the total) I set the StoreResult.Success to false. This is enough to make the grid stay with the same rows but its like the store actually went to that page, because the Store.currentPage on js is the same page number that does not exists (in the example it would be 2222) and the PagingToolbar shows this page on the page 'selector'.
There's someway to really cancel the page from 'turning' in my cenario?
Example:
In a GridPanel of mine, I have a Store and a PagingToolbar. The Store uses a AjaxProxy. In the method that is called in the proxy I return a StoreResult.
I don't want to do a count on my tables, so everytime I set the StoreResult.Total to int.MaxValue, except when i know its the last page. this way the button 'next page' stays able to click when i know it's not the last page and disable when i do, and i hide the 'last page' button.
But when i put a number of page that don't exists (for example: 2222) and he tries to select data for that page (because it's within the total) I set the StoreResult.Success to false. This is enough to make the grid stay with the same rows but its like the store actually went to that page, because the Store.currentPage on js is the same page number that does not exists (in the example it would be 2222) and the PagingToolbar shows this page on the page 'selector'.
There's someway to really cancel the page from 'turning' in my cenario?
Example:
//To build the Grid...
{
GridPanel grid = new GridPanel();
Store store = new Store { ID = "test_store" };
store.RemoteSort = true;
store.PageSize = 33;
AjaxProxy proxy = new AjaxProxy();
proxy.StartParam = "startIndex";
proxy.LimitParam = "pageSize";
proxy.PageParam = "pageNumber";
proxy.SortParam = "ordenacao";
proxy.ActionMethods.Read = HttpMethod.POST;
proxy.Reader.Add(new JsonReader { Root = "data", TotalProperty = "total", MessageProperty = "message" });
proxy.Url = "/Entidade/CarregarRegistros/";
store.Proxy.Add(proxy);
grid.Store.Add(abastecedor);
PagingToolbar pagingToolbar = new PagingToolbar { ID = "test_bar", HideRefresh = true };
pagingToolbar.Listeners.BeforeRender.Handler = "this.getComponent('last').hidden = true;";
pagingToolbar.AfterPageText = string.Empty;
pagingToolbar.BeforePageText = string.Empty;
pagingToolbar.DisplayMsg = "Records from {0} to {1}.";
grid.BottomBar.Add(pagingToolbar);
}
//now for the proxy method...
public StoreResult CarregarRegistros(int startIndex, int pageSize, int pageNumber, string ordenacao, string parametrosDeFiltro, string identificadorDaAplicacao)
{
StoreResult result = new StoreResult();
IList<IEntidade> entityList = //Get the records from the DB, based on the page...
if (entityList.Any())
{
int total;
//IF the number of entities is smaller then the size of the page
if (entityList.Count < pageSize)
{
//get the total based on the current page, because you are on the last one
total = (pageNumber- 1) * pageSize+ entityList.Count;
}
//ELSE (still not the last page)
else
{
//set total to max, because i don't know how many are (and i don't want to know)
total = int.MaxValue;
}
result.Data = entityList;
result.Total = total;
}
//ELSE (if there's no results, the page that he is searching does not exists)
else
{
result.Success = false; // this does not cancel the page from turning, even the DisplayMsg of the toolbar has 'big numbers' on the {0} and {1}.
result.Message = "There are no records on the page that you want to go.";
}
return result;
}
Thanks in advance,
Last edited by Daniil; May 25, 2012 at 1:27 PM.
Reason: [CLOSED]