From edce3b69a0b2de7a02a07bf428e1015d3679b889 Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Mon, 30 Dec 2013 19:44:17 +0800 Subject: [PATCH] Code clean up and relax server side filter's restriction on being in server mode --- backgrid-filter.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/backgrid-filter.js b/backgrid-filter.js index 4ad605a..338ec0e 100644 --- a/backgrid-filter.js +++ b/backgrid-filter.js @@ -119,21 +119,17 @@ if (e) e.preventDefault(); var data = {}; + var query = this.searchBox().val(); + if (query) data[this.name] = query; var collection = this.collection; // go back to the first page on search if (Backbone.PageableCollection && - collection instanceof Backbone.PageableCollection && - collection.mode == "server") { - collection.state.currentPage = collection.state.firstPage; + collection instanceof Backbone.PageableCollection) { + collection.getFirstPage({data: data, reset: true, fetch: true}); } - else { - var query = this.searchBox().val(); - if (query) data[this.name] = query; - } - - collection.fetch({data: data, reset: true}); + else collection.fetch({data: data, reset: true}); }, /** @@ -152,12 +148,10 @@ // go back to the first page on clear if (Backbone.PageableCollection && - collection instanceof Backbone.PageableCollection && - collection.mode == "server") { - collection.state.currentPage = collection.state.firstPage; + collection instanceof Backbone.PageableCollection) { + collection.getFirstPage({reset: true, fetch: true}); } - - collection.fetch({reset: true}); + else collection.fetch({reset: true}); }, /** @@ -332,7 +326,7 @@ }, /** - Clears the search box and reset the collection to its original. + Clears the search box and reset the collection to its original. If the collection is a PageableCollection, clearing will go back to the first page.