使用Backgrid的客户端过滤器扩展执行搜索时,我在从集合中获取正确的totalRecords值时遇到问题。
具体来说,当我使用键盘上的退格键时。
如果我不使用退格,并且打字缓慢,这似乎很好:
//Search input field - keyup event
$("input[name='q']").keyup(function () {
console.log('searchcontainer input - keyup event');
console.log($(this).val())
console.log($(this).val().length)
var key = event.keyCode || event.charCode;
if (key == 8) { //'8' == backspace key
console.log('backspace was keyed!')
//how do I refresh the 'totalRecords' property on the collection?
}
console.log((_myCollection.state.totalRecords || "0") + " records found."));
$("#lblRecordsFound").text((_myCollection.state.totalRecords || "0") + " records found.");
});
当触发退格时,totalRows似乎跳过了集合更新(?)?
使用退格时,如何获取当前的totalRows我需要重置、获取或刷新集合吗?我不确定。帮助
我只需要在任何时候显示在网格中的totalRows。
我最终"更改"了backgrid-filter.js扩展。
我更改了搜索功能,就像这样:
/**
Takes the query from the search box, constructs a matcher with it and
loops through collection looking for matches. Reset the given collection
when all the matches have been found.
If the collection is a PageableCollection, searching will go back to the
first page.
*/
search: function () {
var matcher = _.bind(this.makeMatcher(this.query()), this);
var col = this.collection;
if (col.pageableCollection) col.pageableCollection.getFirstPage({ silent: true });
col.reset(this.shadowCollection.filter(matcher), { reindex: false });
var message = " items found.";
if (col.pageableCollection.state.totalRecords == 1) {
message = " item found.";
}
$("#lblRecordsFound").text((col.pageableCollection.state.totalRecords || "0") + message);
},
工作良好。我不明白为什么Backgrid没有一个公开的属性来方便访问当前的总行。