2016-03-31 8 views
0

У меня возникли проблемы с получением правильного значения totalRecords из моей коллекции при выполнении поиска с расширением фильтра Backgrid Client-Side.Как получить totalRows из Backgrid Поиск на стороне клиента

В частности, когда я использую клавишу backspace на моей клавиатуре.

Если я не использую Забой и типа медленно, это, кажется, работает хорошо:

//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 при использовании backspace? Нужно ли восстанавливать, извлекать или обновлять коллекцию? Я не уверен. Помогите?

Мне просто нужен 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 не имеет открытого свойства для легкого доступа к текущим общим строкам.

 Смежные вопросы

  • Нет связанных вопросов^_^