
|
class App extends Component<AppProps, AppState> {
public elem : HTMLElement;
public flag: any = true;
public autodata: any;
public editOptions: EditSettingsModel = { allowAdding: true, allowDeleting: true, allowEditing: true };
public toolbarOptions: ToolbarItems[] = ['Add', 'Edit', 'Delete', 'Update', 'Cancel'];
public grid: Grid | null;
public datePickerObj: AutoComplete;
public datepickerTemp : IEditCell = {
create:()=>{
this.elem = document.createElement('input');
return this.elem;
},
destroy:()=>{
this.datePickerObj.destroy();
},
read:()=>{
return this.datePickerObj.value;
},
write:(args)=>{
this.flag = false;
var grid = (document.getElementsByClassName('e-grid')[0] as any).ej2_instances[0];
var autoDataSource = cascadeData;
var col = grid.getColumns();
var arr = [];
for(var sam of col) {
arr = arr.concat(DataUtil.distinct(autoDataSource, sam.field));
}
this.autodata = arr;
this.datePickerObj = new AutoComplete({
dataSource: this.autodata,
select: this.selectitem.bind(this)
});
this.datePickerObj.appendTo(this.elem);
}
};
selectitem(args) {
if(args.item.parentElement.id == "gridOrderID_options") {
(document.getElementsByClassName('e-field')[2] as any).focus(); //focus the third column
}
}
dataBound() {
var grid = (document.getElementsByClassName('e-grid')[0] as any).ej2_instances[0];
if (this.flag){
grid.addRecord();//render Grid with edit mode initially
}
}
actionComplete(args){
if (args.requestType == "save") {
var grid = (document.getElementsByClassName('e-grid')[0] as any).ej2_instances[0];
grid.addRecord(); //after saving a record here you can call again a addRecord method to make Grid is in edit mode
}
}
render() {
return (
<div className='control-pane'>
<div className='control-section'>
<GridComponent id='grid' dataSource={[]} actionComplete={this.actionComplete.bind(this)} dataBound={this.dataBound.bind(this)} editSettings={this.editOptions}
toolbar={this.toolbarOptions} height={273} ref={g => this.grid = g}>
<ColumnsDirective>
<ColumnDirective field='OrderID' edit={this.datepickerTemp} headerText='Order ID' width='120'
isPrimaryKey={true}textAlign='Right'></ColumnDirective>
<ColumnDirective field='CustomerID' headerText='Customer Name'
width='150'></ColumnDirective>
<ColumnDirective field='ShipCountry' headerText='Ship Country' width='150'></ColumnDirective>
</ColumnsDirective>
<Inject services={[Edit, Toolbar]} />
</GridComponent>
</div>
</div>
);
}
}
|

|
class App extends Component<AppProps, AppState> {
public elem : HTMLElement;
public flag: any = true;
public autodata: any;
public editOptions: EditSettingsModel = { allowAdding: true, allowDeleting: true, allowEditing: true };
public toolbarOptions: ToolbarItems[] = ['Add', 'Edit', 'Delete', 'Update', 'Cancel'];
public grid: Grid | null;
public mousedown: any = false;
public datePickerObj: AutoComplete;
public datepickerTemp : IEditCell = {
create:()=>{
this.elem = document.createElement('input');
return this.elem;
},
destroy:()=>{
this.datePickerObj.destroy();
},
read:()=>{
return this.datePickerObj.value;
},
write:(args)=>{
this.flag = false;
var grid = (document.getElementsByClassName('e-grid')[0] as any).ej2_instances[0];
var autoDataSource = cascadeData;
var col = grid.getColumns();
var arr = [];
for(var sam of col) {
arr = arr.concat(DataUtil.distinct(autoDataSource, sam.field));
}
this.autodata = arr;
this.datePickerObj = new AutoComplete({
dataSource: this.autodata,
select: this.selectitem.bind(this)
});
this.datePickerObj.appendTo(this.elem);
}
};
selectitem(args) {
if(args.item.parentElement.id == "gridOrderID_options") {
(document.getElementsByClassName('e-field')[2] as any).focus();
}
}
dataBound() {
var grid = (document.getElementsByClassName('e-grid')[0] as any).ej2_instances[0];
if (this.flag){
grid.addRecord();
}
}
actionComplete(args){
if (args.requestType == "add") {
setTimeout(function(){
(document.getElementsByClassName('e-field')[0] as any).focus(); //focus the first column
});
}
if (args.requestType == "save") {
var grid = (document.getElementsByClassName('e-grid')[0] as any).ej2_instances[0];
grid.addRecord();
}
}
load(){
var grid = (document.getElementsByClassName('e-grid')[0] as any).ej2_instances[0];
grid.element.addEventListener('mousedown', function (e) {
this.mousedown = false;
}.bind(this))
grid.element.addEventListener('keydown', function (e) {
if(e.key == "Enter"){
this.mousedown = true;
}
}.bind(this))
}
begin(args) {
if (args.requestType == "save" && !this.mousedown) {
args.cancel = true; //it helps to prevent the saving when you click outside of the row in the Grid
}
}
render() {
return (
<div className='control-pane'>
<div className='control-section'>
<GridComponent id='grid' dataSource={[]} actionBegin={this.begin.bind(this)} load={this.load.bind(this)} actionComplete={this.actionComplete.bind(this)} dataBound={this.dataBound.bind(this)} editSettings={this.editOptions}
toolbar={this.toolbarOptions} height={273} ref={g => this.grid = g}>
<ColumnsDirective>
<ColumnDirective field='OrderID' edit={this.datepickerTemp} headerText='Order ID' width='120'
isPrimaryKey={true}textAlign='Right'></ColumnDirective>
<ColumnDirective field='CustomerID' headerText='Customer Name'
width='150'></ColumnDirective>
<ColumnDirective field='ShipCountry' headerText='Ship Country' width='150'></ColumnDirective>
</ColumnsDirective>
<Inject services={[Edit, Toolbar]} />
</GridComponent>
</div>
</div>
);
}
}
|