Skip to content

Commit

Permalink
* #7. fix search with onKeyUp
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Mar 21, 2017
1 parent 8399dd0 commit 49b3732
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
21 changes: 11 additions & 10 deletions src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ class Header extends React.Component {
if (columnsSearch[data] !== CommonConstants.UNDEFINED) {
val = columnsSearch[data];
}
return (
<div className={styles.gt_th_box}>
<input
data-index={data}
name={data}
onChange={doDiscreteSearch}
placeholder={columns[sortId].discreteSearchValue(data)}
value={val} />
</div>
);
return (
<div className={styles.gt_th_box}>
<input
data-index={data}
name={data}
onKeyUp={doDiscreteSearch}
onChange={doDiscreteSearch}
placeholder={columns[sortId].discreteSearchValue(data)}
value={val} />
</div>
);
}
return <div className={styles.gt_th_box}>{children}</div>;
}
Expand Down
14 changes: 8 additions & 6 deletions src/components/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class Main extends React.Component {
var period = this.nowMillis - this.lastTimeKeyup;

if (len > 0 || (len === 0 && val === '')) { // do search
// this.setState({
// [name]: val
// });
this.setState({
[name]: val
});
if (this.nothing === true && val === '') {
return; // exit - user pressed not a symbol keys or teared down
}
Expand Down Expand Up @@ -96,9 +96,9 @@ class Main extends React.Component {
this.c++;
}
this.nothing = false;
// this.setState({
// dataSearch: nJson
// });
this.setState({
dataSearch: nJson
});
}
this.lastTimeKeyup = this.nowMillis;
}
Expand Down Expand Up @@ -470,9 +470,11 @@ class Main extends React.Component {
})
});
if (this.nothing === true && val === '') {
console.log('nothing');
return; // exit - user pressed not a symbol keys or teared down
}
if (this.nothing === false && val === '') { // rebuild full table if teared down
console.log('teared down');
this.createTable(this.jsonData, this.state.sortedButtons);
this.nothing = true;
return;
Expand Down

0 comments on commit 49b3732

Please sign in to comment.