ExtJS 4 - How to disable 'next' & 'last' icons in the paging toolbar when no records present in grid?

我是研究僧i 提交于 2019-12-08 12:13:19

问题


I have a grid with paging toolbar at the bottom and a 'Load' button at the top which can be used to load records in the grid.

Thus, initially there are no values present in the grid, but in such condition too the paging toolbar displays Page 1 of 1, and also the icons to go to 'next' or 'last' page are enabled.

Due to this, when user clicks any of these icons, then, though the records are not loaded but internally the values of 'page' and 'start' are set as NaN and if then user clicks at 'Load' button then these NaN values get passed to the server which is not what is expected.

That is, ideally, it should pass page=0&start=0 where as it passes page=NaN&start=NaN. The server doesn't recognize these values and throws error.

One quick fix for this is the modification of the code at the server side, but currently that is beyond the scope of our team work and thus I was wondering that how could following be acheived:

Q) How to disable 'next', 'last' icons at paging toolbar when the grid has no records?

Or,

Q) How to modify the values of 'page' and 'start' variables before loading the store so that we can pass 0 instead of NaN?

I tried accessing these parameters in beforeload event of the grid store, but there I could find the properties like - startParam or pageParam - displaying the name of parameter, but couldn't locate any method of accessing/modifying there values.

Does anyone have an idea on this?

Thanks in advance.

PS: ExtJS Version used is 4.


回答1:


One possible solution could be using

store.loadPage(1);

instead of store.load();.

The second possible solution is to make toolbar initialy disabled and enable it when data is loaded:

var grid = Ext.create('Ext.grid.Panel', {
    // ...
    store: store,
    dockedItems: [{
        xtype: 'pagingtoolbar',
        store: store,
        dock: 'bottom',
        disabled: true
    }]
});
store.on('load', function(){
  grid.down('pagingtoolbar').enable();
});



回答2:


check the total count in response, if it is not returning zero when your grid is empty then such errors will occur.



来源:https://stackoverflow.com/questions/7647185/extjs-4-how-to-disable-next-last-icons-in-the-paging-toolbar-when-no-rec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!