Skip to content

fix issue13 #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,25 @@ Example:

type: `array`


### `header`

Wether show header infomation. Defaults true. you can set it to false or object as argument

if `header` is true, header will show. **Default**
if `header` is false, header won't show.
if `header` is blank object, header won't show too.
if `header` is equal to above like-code, header will show.

Example:
```javascript
{
"first": "Category",
"second": "Operator",
"third": "Value"
}

```
type: `object` or `bool`
defaultValue: `true`

6 changes: 6 additions & 0 deletions example/src/ExampleTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ var ExampleTable = React.createClass({
value: 'Dec 8, 1980 10:50 PM',
},
],
header: {
first: "Category1",
second: "Operator1",
third: "Value1"
},
}
},

Expand Down Expand Up @@ -81,6 +86,7 @@ var ExampleTable = React.createClass({
}}
onChange={this.updateFilter}
value={this.state.filter}
header={this.state.header}
/>
<GriddleWithCallback
getExternalResults={this.getJsonData} filter={JSON.stringify(this.state.filter)}
Expand Down
45 changes: 37 additions & 8 deletions src/tokenizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@ export default class Tokenizer extends Component {
* ```
*/
operators: PropTypes.object,
/**
* A mapping of headers to show
* Example:
* ```javascript
* {
* "first": "Category",
* "second": "Operator",
* "third": "Value"
* }
* ```
*/
header: PropTypes.oneOfType([
PropTypes.object,
PropTypes.bool,
]),
}

static defaultProps = {
Expand All @@ -182,6 +197,7 @@ export default class Tokenizer extends Component {
number: [ `==`, `!=`, `<`, `<=`, `>`, `>=` ],
date: [ `==`, `!=`, `<`, `<=`, `>`, `>=` ],
},
header: true,
}

constructor( ...args ) {
Expand All @@ -190,12 +206,25 @@ export default class Tokenizer extends Component {
this._onKeyDown = this._onKeyDown.bind( this );
this._getOptionsForTypeahead = this._getOptionsForTypeahead.bind( this );
this._removeTokenForValue = this._removeTokenForValue.bind( this );
}

state = {
selected: this.getStateFromProps( this.props ),
category: '',
operator: '',
let header = {
first: 'Category',
second: 'Operator',
third: 'Value',
};

if ( typeof this.props.header === 'boolean' ) {
header = this.props.header ? header : {};
} else if ( Object.prototype.toString.call( this.props.header ) === '[object Object]' ) {
header = this.props.header;
}

this.state = {
selected: this.getStateFromProps( this.props ),
category: '',
operator: '',
header,
};
}

componentDidMount() {
Expand Down Expand Up @@ -268,12 +297,12 @@ export default class Tokenizer extends Component {

_getHeader() {
if ( this.state.category === '' ) {
return 'Category';
return this.state.header.first;
} else if ( this.state.operator === '' ) {
return 'Operator';
return this.state.header.second;
}

return 'Value';
return this.state.header.third;
}

_getCategoryType( category ) {
Expand Down
2 changes: 1 addition & 1 deletion src/typeahead/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Typeahead extends Component {

static defaultProps = {
options: [],
header: 'Category',
header: '',
datatype: 'text',
customClasses: {},
defaultValue: '',
Expand Down
4 changes: 3 additions & 1 deletion src/typeahead/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ export default class TypeaheadSelector extends Component {
)
, this );

const first = this.props.header ? ( <li className="header">{ this.props.header }</li> ) : null;

return (
<ul className={ classList }>
<li className="header">{ this.props.header }</li>
{ first }
{ results }
</ul>
);
Expand Down