@@ -6,26 +6,30 @@ class TextFilter extends Component {
66 super ( props ) ;
77 this . filter = this . filter . bind ( this ) ;
88 this . timeout = null ;
9+ this . state = {
10+ value : this . props . defaultValue || ''
11+ } ;
912 }
1013
1114 filter ( event ) {
1215 if ( this . timeout ) {
1316 clearTimeout ( this . timeout ) ;
1417 }
1518 const filterValue = event . target . value ;
19+ this . setState ( ( ) => { return { value : filterValue } ; } ) ;
1620 this . timeout = setTimeout ( ( ) => {
1721 this . props . filterHandler ( filterValue , Const . FILTER_TYPE . TEXT ) ;
1822 } , this . props . delay ) ;
1923 }
2024
2125 cleanFiltered ( ) {
2226 const value = this . props . defaultValue ? this . props . defaultValue : '' ;
23- this . refs . inputText . value = value ;
27+ this . setState ( ( ) => { return { value } ; } ) ;
2428 this . props . filterHandler ( value , Const . FILTER_TYPE . TEXT ) ;
2529 }
2630
2731 applyFilter ( filterText ) {
28- this . refs . inputText . value = filterText ;
32+ this . setState ( ( ) => { return { value : filterText } ; } ) ;
2933 this . props . filterHandler ( filterText , Const . FILTER_TYPE . TEXT ) ;
3034 }
3135
@@ -36,20 +40,26 @@ class TextFilter extends Component {
3640 }
3741 }
3842
43+ componentWillReceiveProps ( nextProps ) {
44+ if ( nextProps . defaultValue !== this . props . defaultValue ) {
45+ this . applyFilter ( nextProps . defaultValue || '' ) ;
46+ }
47+ }
48+
3949 componentWillUnmount ( ) {
4050 clearTimeout ( this . timeout ) ;
4151 }
4252
4353 render ( ) {
44- const { placeholder, columnName, defaultValue , style } = this . props ;
54+ const { placeholder, columnName, style } = this . props ;
4555 return (
4656 < input ref = 'inputText'
4757 className = 'filter text-filter form-control'
4858 type = 'text'
4959 style = { style }
5060 onChange = { this . filter }
5161 placeholder = { placeholder || `Enter ${ columnName } ...` }
52- defaultValue = { defaultValue ? defaultValue : '' } />
62+ value = { this . state . value } />
5363 ) ;
5464 }
5565}
0 commit comments