[英]In knockout Change Paging when Data is changed
In knockout I wish to change/ refresh Paging when data is changed. 在淘汰赛中,我希望在数据更改时更改/刷新分页。 For example: I have a data set of 100[5 Records per Page] and I am on Page 10. Now with some more search Data is changed from 100 to 5 and I am on Page 10, but when data is changed I want paging to be on First page.
例如:我的数据集为100 [每页5条记录],我在第10页上。现在有了更多搜索,数据从100更改为5,我在第10页上,但是当数据更改时,我要分页在首页上。 ie Paging to be refreshed.
即分页要刷新。
Here is my [Fiddle] ( https://jsfiddle.net/975ncawv/281/ ) 这是我的[小提琴]( https://jsfiddle.net/975ncawv/281/ )
MyVM.prototype.loadData = function(rawData) {
this.items(rawData.map(RowModel.fromRawDataPoint));
};
ko.applyBindings(new MyVM(myData));
but when data is changed
但是当数据改变时
this.items.subscribe( /* ... */ )
I want paging to be on First page
我希望分页显示在首页上
this.pageNumber(0)
Put together: 放在一起:
this.items.subscribe(function() {
this.pageNumber(0);
}, this);
I don't see any logic concerning the search data, but I'd expect something along the lines of: 我没有发现与搜索数据有关的任何逻辑,但是我希望能做到以下几点:
this.filteredItems = ko.pureComputed(function() {
return this.items().filter(/* ... */);
}, this);
Once implemented, you can change the subscribe to items
to be on filteredItems
to make sure you reset both when the data source changes as well as when the search query changes. 一旦实现,就可以将订阅
items
更改为filteredItems
,以确保在数据源更改以及搜索查询更改时都重置。
Two things need to be changed inside the loadData
function. 在
loadData
函数内部需要更改两件事。
all
observableArray needs to be updated with the new values of items
, since it gets the values in a similar fashion in line 65. all
observableArray在第65行中以类似方式获取值,因此需要使用items
的新值进行更新。 pageNumber
needs to be reset to 0, since paginated
and all
are listening to it through the computed function. pageNumber
需要重设为0,因为已paginated
并且all
都在通过计算函数来监听它。 (And the table is displaying the values of paginated
). paginated
的值)。 It would look like this updated fiddle . 看起来像是这个更新过的小提琴 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.