-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiSelect.tsx
81 lines (70 loc) · 1.78 KB
/
MultiSelect.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import * as React from "react";
import AsyncSelect from 'react-select/async';
export interface IProps {
initialValues: any;
isControlVisible: boolean;
isControlDisabled: boolean;
displayValueField: any;
displayFieldLabel: any;
columns: any;
topCount: any;
filterField: any;
entityName: any;
value: any;
onChange: (value:string) => void;
onSearch: (value:string) => void;
records: any
}
export interface IState {
value: string;
}
export class MultiSelectControl extends React.Component<IProps, IState> {
constructor(props: Readonly<IProps>) {
super(props);
this.state = { value: props.value};
}
componentWillReceiveProps(p: IProps)
{
this.setState({value : (p.value)});
}
onChange = (ob: any) =>
{
if (ob == null) {
this.setState({value : "" });
this.props.onChange("");
return;
};
var res = ob.map((e: any) => e[this.props.displayValueField]).join(",");
this.setState({value : res });
this.props.onChange(res);
}
loadOptions:any = async (inputValue: string) => {
const res = this.props.onSearch(inputValue);
return res;
}
public render(): JSX.Element
{
const selectStyles = { menuPortal: (zindex: any) => ({ ...zindex, zIndex: 9999}) };
if (this.props.isControlVisible)
{
return (
<div>
<AsyncSelect
isMulti={true}
menuPortalTarget={document.body}
defaultOptions
styles={selectStyles}
getOptionLabel={e => e[this.props.displayFieldLabel]}
getOptionValue={e => e[this.props.displayValueField]}
loadOptions={this.loadOptions}
isDisabled={this.props.isControlDisabled}
onChange={this.onChange}
defaultValue={this.props.initialValues}
/></div>
)
}
else{
return (<></>);
};
}
}