Ext js 动态更新分页工具栏的总数
这应该相当简单,但我还没有找到方法。
我正在使用 ExtJs v.3.3。
我有一个网格面板,允许使用上下文菜单删除记录。
网格有一个附加到面板存储的分页工具栏。
删除过程向服务器发送一个ajax请求,成功后我从存储中删除记录(使用remove方法)。
问题是分页工具栏不反映商店中的更改,即在商店重新加载之前记录总数保持不变。
有没有办法可以设置分页工具栏中的记录总数?
谢谢
This should be fairly simple but I haven't found a way to do it yet.
I am using a ExtJs v.3.3.
I have a grid panel that allows record deletion with context menu.
The grid has a paging toolbar that is attached to the panel store.
The deletion process sends an ajax request to the server, on success I remove the record from the store (using the remove method).
The thing is that the paging toolbar does not reflect the change in the store , that is the total amount of records is unchanged until the store is reloaded.
Is there any way to set the total amount of records in the paging toolbar?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
这对于 ExtJs 版本 4.1.3 来说就像一个魅力。
This works like a charm for ExtJs ver 4.1.3.
数据库中的数据被删除后,是否无法在响应中返回totalProperty值?
编辑:
您需要首先正确构建您的响应。根据分页工具栏的 API 文档,它应该是这样的。
如果使用商店的 autoLoad 配置:
从服务器发回的数据包将具有以下形式:
Are you not able to return the totalProperty value in the response after the data has been deleted in the DB?
EDIT:
You'll need to get your response constructed properly first. This is how it should look according to the API Docs for the Paging Toolbar.
If using store's autoLoad configuration:
The packet sent back from the server would have this form:
这对我来说效果很好:
This worked fine for me:
当从第三方 api 获取结果时,我遇到了类似的问题,该第三方 api 有一个单独的项目计数 url。我创建了一个继承自 pagingtoolbar 的新类,并附加了 updatePager() 函数:
});
在添加到扩展坞时,我向其中添加了一个 itemId
,我向关联的商店添加了一个 setTotalCount() 函数:
然后,当您想要更新它时,请调用 store.setTotalCount(total),然后调用 pager.updatePager()。请记住,您将首先使用
pager = grid_view.down('#pager_id');之类的方法获取寻呼机
I had a similar problem when getting results from a third party api which had a separate url for the item count. I created a new class inheriting from the pagingtoolbar with an additional updatePager() function:
});
I added an itemId to it when adding to the dock
I added a setTotalCount() function to the associated store:
Then when you want to update it call store.setTotalCount(total) and then pager.updatePager(). Remember that you will have get the pager first using something like
pager = grid_view.down('#pager_id');
“删除过程向服务器发送 ajax 请求,成功后我从存储中删除记录(使用删除方法)...” - 这表明您拥有处理“删除”操作的方法 - 如果您使用 Ext .PagingToolbar - 只需再添加一行,如下所示:
(this).YourPagingToolbar.doRefresh()
我将 (this) 放入 () 中,因为您没有提供任何代码示例,所以我不确定您是如何定义的它
"The deletion process sends an ajax request to the server, on success I remove the record from the store (using the remove method)..." - this suggest that you got method that handle "delete" action - and if you using Ext.PagingToolbar - just add one more line like this:
(this).YourPagingToolbar.doRefresh()
I put (this) in () because you did not provide any code example so I not sure how you defined it
商店.totalLength = 商店.totalLength - 1;
这将改变商店中的总行数,但我不确定分页工具栏是否会反映此更改。
store.totalLength = store.totalLength - 1;
this would change the number of total rows in the store, but I am not sure if this change would be reflected by the paging toolbar.
当我尝试使用多个分页工具栏(网格的顶部/底部)时,我遇到了类似的情况。分页工具栏中唯一更新显示的位置在商店“加载”时被调用。因此,您可以手动触发事件(但要注意意想不到的后果!)。就我而言,当从我的工具栏之一的 beforechange 侦听器运行时,效果很好:
或者...您可以覆盖或扩展 PagingToolbar 以添加一个公共方法,该方法将调用或覆盖 onLoad 函数
I had a similar situation when trying to use multiple paging toolbars (top/bottom of grid). The only place in the paging toolbar that updates the display gets called on store 'load'. So you can fire the event manually (but beware of unintended consequences!). In my case this worked well when run from the beforechange listener of one of my toolbars:
Or ... you could override or extend the PagingToolbar to add a public method which would call or override the onLoad function
如果分页工具栏中有多个页面,并从商店本地执行插入/删除操作,则使用以下代码片段。
If you have multiple pages in paging toolbar, and perform insert/remove operation locally from store then use below snippet.