2016-03-31 30 views
0

我无法执行与Backgrid的客户端过滤器扩展搜索时从我的收藏得到正确的总记录值totalRows。如何从Backgrid客户端搜索

具体来说,当我在我的键盘上使用退格键。

如果我不使用退格,慢慢打字,这似乎很好地工作:

//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。

回答

0

我结束了“改变”的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没有暴露的属性可以轻松访问当前的总行数。