Skip to content

Commit

Permalink
Merge pull request #101 from joshsoftware/template_update
Browse files Browse the repository at this point in the history
Ref #87 change template after FilterJS initialization
  • Loading branch information
jiren committed Oct 22, 2015
2 parents a85ea37 + 080fdf6 commit 63a4ad8
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1,696 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,20 @@ fjs.removeRecords([1,2,3]);
fjs.removeRecords({'year.$gt': 1980, 'rating': 8.5});
```
## Change Template dynamically and Rebuild
If you want to change the template dynamically but do not want to re-render the view (you many choose to render the template yourself) then just pass the template name to `setTemplate` function.
```javascript
fjs.setTemplate('#movie-list-template');
```
If you want to re-render the new template then pass a second paramater as `true`. This will render the container with the data using the new template specified and apply the filtering.
```javascript
fjs.setTemplate('#movie-list-template', true);
```
## Build and Development
- `npm install gulp -g`
Expand Down
18 changes: 15 additions & 3 deletions dist/filter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* filter.js
* 2.1.0 (2015-09-27)
* 2.1.0 (2015-10-17)
*
* Released under the MIT license
* http://opensource.org/licenses/MIT
Expand Down Expand Up @@ -864,14 +864,15 @@
this.callbacks = this.opts.callbacks || {};
this.$container = $(container);
this.view = this.opts.view || renderRecord;
this.templateFn = templateBuilder($(this.opts.template).html());
this.criterias = [];
this._index = 1;
this.appendToContainer = this.opts.appendToContainer || appendToContainer;
this.has_pagination = !!this.opts.pagination;
this.search_text = '';
this.anyFilterSelected = false;

this.setTemplate(this.opts.template);

$.each(this.opts.criterias || [], function(){
self.addCriteria(this);
});
Expand Down Expand Up @@ -1407,7 +1408,7 @@

F.initPagination = function(){
var self = this,
opts = this.opts.pagination;
opts = this.opts.pagination;

if(!opts.perPage){
opts.perPage = {}
Expand Down Expand Up @@ -1450,6 +1451,17 @@
}
};

F.setTemplate = function(template, rebuild) {
this.templateFn = templateBuilder($(template).html());
if(rebuild === true) {
this.$container.empty();

this.render(this.records);
this.filter();
}
};



var Paginator = function(recordsCount, opts, onPagination) {
var paginationView;
Expand Down
Loading

0 comments on commit 63a4ad8

Please sign in to comment.