2016-03-31 31 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沒有暴露的屬性可以輕鬆訪問當前的總行數。