@Component({
selector: 'app-container',
template: `<ejs-grid #grid [dataSource]='data' id="gridcomp"
allowPaging='true' [editSettings]='editSettings' [toolbar]='toolbarItems' height='220px'>
<e-columns>
. . .
<e-column field='interval' headerText='interval' [edit]='datepickerTemplate' width='220'></e-column>
</e-columns>
</ejs-grid>`
})
export class AppComponent implements OnInit {
. . .
public intl: Internationalization = new Internationalization();
@ViewChild('grid')
public grid: GridComponent;
ngOnInit(): void {
. . .
this.datepickerTemplate = {
create: () => {
this.div = document.createElement('div');
this.div.style.width = '50%';
this.elem1 = document.createElement('input');
this.div.appendChild(this.elem1);
this.elem2 = document.createElement('input');
this.div.appendChild(this.elem2);
return this.div;
},
read: () => {
// converting date object into string with required format
const string1: string = this.intl.formatDate(this.datePickerObj1.value,
{ format: 'yyyy-MM-dd' });
const string2: string = this.intl.formatDate(this.datePickerObj2.value,
{ format: 'yyyy-MM-dd' });
const interval = string1 + '/' + string2;
return interval;
},
destroy: () => {
this.datePickerObj1.destroy();
this.datePickerObj2.destroy();
},
write: (args: { rowData: Object, column: any }) => {
// here data will be like “2018-10-16/2018-10-20”
const dates: string = args.rowData[args.column.field].split('/');
this.datePickerObj1 = new DatePicker({
value: new Date(dates[0]),
floatLabelType: 'Never'
});
this.datePickerObj1.appendTo(this.elem1);
this.datePickerObj2 = new DatePicker({
value: new Date(dates[1]),
floatLabelType: 'Never'
});
this.datePickerObj2.appendTo(this.elem2);
}
};
}
}
|
ej2-base/styles/material.css
ej2-grids/styles/material.css
ej2-buttons/styles/material.css
ej2-popups/styles/material.css
ej2-navigations/styles/material.css
ej2-dropdowns/styles/material.css
ej2-lists/styles/material.css
ej2-inputs/styles/material.css
ej2-calendars/styles/material.css
|
@Component({
selector: 'control-content',
template: `<ejs-grid #grid [dataSource]='data' id="gridcomp"
allowPaging='true' [editSettings]='editSettings' [toolbar]='toolbarItems' height='220px'>
<e-columns>
<e-column field='Freight' headerText='Freight' width='120' type='number' allowEditing='false' format='C2' editType='numericedit'></e-column>
. . .
</e-columns>
</ejs-grid>`,
})
export class BatchEditComponent implements OnInit {
. . .
// Numerictextbox template for grid edit
public numericTextBoxObj: NumericTextBox;
public numericTextBoxTemplate: IEditCell = {
create: (args: { element: Element, column: Column }) => {
this.elem1 = document.createElement('input');
return this.elem1;
},
read: () => {
this.numericTextBoxObj.element.blur();
return this.numericTextBoxObj.value;
},
write: (args: { element: Element, column: Column, rowData: any }) => {
console.log("args", args)
this.numericTextBoxObj = new NumericTextBox({
validateDecimalOnType: true,
value: args.rowData.EmployeeID,
});
this.numericTextBoxObj.appendTo(this.elem1);
}
}
ngOnInit(): void {
. . .
this.grid.cellEdit.subscribe(i => this.renderCellTemplateByDataType(i))
}
private renderCellTemplateByDataType(args) {
args.columnObject.edit = this.numericTextBoxTemplate;
}
} |
ngOnInit(): void {
. . . .
this.datepickerTemplate = {
create: () => {
. . . .
return this.div;
},
read: () => {
console.log("reading time picker")
return '';
},
destroy: () => {
this.timePickerObj1.destroy();
this.timePickerObj2.destroy();
},
write: (args: { rowData: Object, column: any }) => {
this.div.setAttribute('e-mappinguid', args.column.uid);
this.timePickerObj1 = new TimePicker({
value: new Date('8/3/2017 ' + '13:00')
});
. . . .
}
};
}
|