如何从 Backgrid 客户端搜索中获取 totalRows
How to get totalRows from Backgrid Client-Side search
在使用 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 似乎跳过了集合更新(?)?
如何在使用退格键时获取当前的总行数?我是否需要重置、获取或刷新集合?我不确定。有帮助吗?
我只需要网格中当前显示的总行数,随时都可以。
我结束了 "altering" 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 没有公开的 属性 以便于访问当前的总行数。
在使用 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 似乎跳过了集合更新(?)?
如何在使用退格键时获取当前的总行数?我是否需要重置、获取或刷新集合?我不确定。有帮助吗?
我只需要网格中当前显示的总行数,随时都可以。
我结束了 "altering" 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 没有公开的 属性 以便于访问当前的总行数。