This repository was archived by the owner on Jul 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdialog-template.tsx
More file actions
170 lines (161 loc) · 8.84 KB
/
dialog-template.tsx
File metadata and controls
170 lines (161 loc) · 8.84 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import * as React from 'react';
import { GridComponent, ColumnsDirective, ColumnDirective, Page, Toolbar,
Edit, Inject, DialogEditEventArgs } from '@syncfusion/ej2-react-grids';
import { SampleBase } from '../common/sample-base';
import { data as orderData } from './data';
import { NumericTextBoxComponent } from '@syncfusion/ej2-react-inputs';
import { DatePickerComponent } from '@syncfusion/ej2-react-calendars';
import { DropDownListComponent } from '@syncfusion/ej2-react-dropdowns';
import { DataUtil } from '@syncfusion/ej2-data';
import { Browser, extend } from '@syncfusion/ej2-base';
import './dialog-temp.css';
export class DialogTemplate extends SampleBase<{}, {}> {
public toolbarOptions: any = ['Add', 'Edit', 'Delete'];
public editSettings: any = { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Dialog', template: this.dialogTemplate };
public validationRules = { required: true };
public pageSettings: Object = {pageCount: 5};
dialogTemplate(props: IOrderModel): any {
return (<DialogFormTemplate {...props} />);
}
actionComplete(args: DialogEditEventArgs): void {
if ((args.requestType === 'beginEdit' || args.requestType === 'add')) {
if (Browser.isDevice) {
args.dialog.height = window.innerHeight - 90 + 'px';
(args.dialog as any).dataBind();
}
}
}
render() {
return (
<div className='control-pane'>
<div className='control-section'>
<GridComponent dataSource={orderData} toolbar={this.toolbarOptions} allowPaging={true} editSettings={this.editSettings} pageSettings={this.pageSettings}
actionComplete={this.actionComplete.bind(this)}>
<ColumnsDirective>
<ColumnDirective field='OrderID' headerText='Order ID' width='120' textAlign='Right' validationRules={this.validationRules} isPrimaryKey={true}></ColumnDirective>
<ColumnDirective field='CustomerName' headerText='Customer Name' width='150' validationRules={this.validationRules}></ColumnDirective>
<ColumnDirective field='Freight' headerText='Freight' width='120' format='C2' textAlign='Right'></ColumnDirective>
<ColumnDirective field='OrderDate' headerText='Order Date' format='yMd' width='170' ></ColumnDirective>
<ColumnDirective field='ShipCountry' headerText='Ship Country' width='150' ></ColumnDirective>
</ColumnsDirective>
<Inject services={[Page, Toolbar, Edit]} />
</GridComponent>
<div id="action-description">
<p>This sample demonstrates CRUD operations in Grid with <code>Dialog Template</code> feature. You can perform CRUD operations as follows,</p>
<ul>
<li><code>Add</code> - To add new record, click Add toolbar button </li>
<li><code>Edit</code> - To edit record, double click a row or click toolbar Edit button after selected a row </li>
<li><code>Delete</code> - To delete record, click toolbar Delete button after selected a row </li>
<li><code>Update</code>,<code>Cancel</code> - You can save or discard changes by click toolbar Update and cancel button respectively</li>
</ul>
</div>
<div id="description">
<p> The Grid supports CRUD operations. This CRUD operations can be configured in Grid using
<code><a target="_blank" className="code" href="http://ej2.syncfusion.com/react/documentation/grid/api-editSettings.html">
editSettings</a></code>.
</p>
<p>
In this demo, Dialog template is enabled for editing
by defining <code><a target="_blank" className="code"
href="http://ej2.syncfusion.com/documentation/grid/api-editSettings.html#mode-string">
editSettings.mode
</a></code> as <code>Dialog</code> and <code><a target="_blank" className="code"
href="http://ej2.syncfusion.com/documentation/grid/api-editSettings.html#mode-string">
editSettingsTemplate </a></code> as a React template.
You can start editing by double clicking a row or clicking on toolbar's <code>Edit</code> button,
then the currently selected row will be shown on a dialog with custom elements and you can change the row values and save edited data to the datasource.
</p>
<p style={{ fontWeight: 500 }}>Injecting Module:</p>
<p>
Grid features are segregated into individual feature-wise modules. To use editing feature, we need to inject
<code><a target="_blank" className="code"
href="http://ej2.syncfusion.com/react/documentation/grid/api-edit.html">
Edit
</a></code> module into the <code>services</code>.
</p>
</div>
</div>
</div>
);
}
}
export class DialogFormTemplate extends React.Component<{}, {}> {
private shipCityDistinctData: any = DataUtil.distinct(orderData, 'ShipCity', true);
private shipCountryDistinctData: any = DataUtil.distinct(orderData, 'ShipCountry', true );
private orderID: HTMLInputElement;
private customerName: HTMLInputElement;
constructor(props) {
super(props);
this.state = extend({}, {}, props, true);
}
onChange(args: any): void {
let key: string = args.target.name;
let value: string = args.target.value;
this.setState({[key]: value});
}
componentDidMount() {
let state: IOrderModel = this.state;
// Set initail Focus
state.isAdd ? this.orderID.focus() : this.customerName.focus();
}
render(): any {
let data: IOrderModel = this.state;
return (<div>
<div className="form-row">
<div className="form-group col-md-6">
<div className="e-float-input e-control-wrapper">
<input ref={input=> this.orderID = input} id="OrderID" name="OrderID" type="text" disabled={!data.isAdd} value={data.OrderID} onChange={this.onChange.bind(this)} />
<span className="e-float-line"></span>
<label className="e-float-text e-label-top"> Order ID</label>
</div>
</div>
<div className="form-group col-md-6">
<div className="e-float-input e-control-wrapper" >
<input ref={input=> this.customerName = input} value={data.CustomerName} id="CustomerName" name="CustomerName" type="text" onChange={this.onChange.bind(this)} />
<span className="e-float-line"></span>
<label className="e-float-text e-label-top">Customer Name</label>
</div>
</div>
</div>
<div className="form-row">
<div className="form-group col-md-6">
<NumericTextBoxComponent id="Freight" format='C2' value={data.Freight} placeholder="Freight" floatLabelType='Always'></NumericTextBoxComponent>
</div>
<div className="form-group col-md-6">
<DatePickerComponent id="OrderDate" value={data.OrderDate} placeholder="Order Date" floatLabelType='Always'></DatePickerComponent>
</div>
</div>
<div className="form-row">
<div className="form-group col-md-6">
<DropDownListComponent id="ShipCountry" value={data.ShipCountry} dataSource={this.shipCountryDistinctData}
fields={{text: 'ShipCountry', value: 'ShipCountry' }} placeholder="Ship Country"
popupHeight='300px' floatLabelType='Always'></DropDownListComponent>
</div>
<div className="form-group col-md-6">
<DropDownListComponent id="ShipCity" value={data.ShipCity} dataSource={this.shipCityDistinctData}
fields={{text: 'ShipCity', value: 'ShipCity' }} placeholder="Ship City"
popupHeight='300px' floatLabelType='Always'></DropDownListComponent>
</div>
</div>
<div className="form-row">
<div className="form-group col-md-12">
<div className="e-float-input e-control-wrapper">
<textarea id="ShipAddress" name="ShipAddress" value={data.ShipAddress} onChange={this.onChange.bind(this)} ></textarea>
<span className="e-float-line"></span>
<label className="e-float-text e-label-top">Ship Address</label>
</div>
</div>
</div>
</div>);
}
}
export interface IOrderModel {
OrderID?: number;
CustomerName?: string;
Freight?: number;
OrderDate?: Date;
ShipCity?: string;
ShipCountry?: string;
ShipAddress?: string;
isAdd?: boolean;
}