Skip to content

Commit

Permalink
Merge pull request #56 from spinloop/ce/rerender
Browse files Browse the repository at this point in the history
remount daterangepicker on rerender
  • Loading branch information
skratchdot committed Jan 11, 2016
2 parents 997c76a + 812cf6a commit 2a398de
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ module.exports = React.createClass({
}
},
componentDidMount: function () {
this.initializeDateRangePicker();
},
componentWillUnmount: function () {
this.removeDateRangePicker();
},
removeDateRangePicker: function() {
this.$picker.data('daterangepicker').remove();
},
initializeDateRangePicker: function() {
var $this = this;
$ = (window.jQuery && window.jQuery.fn.daterangepicker)? window.jQuery : $;
$this.$picker = $(this.refs.picker);
Expand All @@ -58,10 +67,12 @@ module.exports = React.createClass({
$this.$picker.on(lcase + '.daterangepicker', $this.makeEventHandler('on' + event));
});
},
componentWillUnmount: function () {
this.$picker.data('daterangepicker').remove();
},
render: function () {
if (this.$picker) {
this.removeDateRangePicker();
this.initializeDateRangePicker();
}

this.setOptionsFromProps();
return React.createElement(
'div',
Expand Down

0 comments on commit 2a398de

Please sign in to comment.