|
[index.js]
import { DatePicker } from '@syncfusion/ej2-calendars';
import { Internationalization } from '@syncfusion/ej2-base'
export class NormalEdit extends SampleBase {
constructor() {
super(...arguments);
this.toolbarOptions = ["Add", "Edit", "Delete", "Update", "Cancel"];
this.data = [
{ OrderID: 10248, CustomerID: "Ana Trujillo", constantType: true, otherFieldType: false, Freight: 32.38, OrderDate: '6/12/2019', ShipCountry: "Berlin" },
{ OrderID: 10249, CustomerID: "Antonio Moreno", constantType: false, otherFieldType: true, Freight: 11.61, OrderDate: '1/15/2019', ShipCountry: "Austria" },
{ OrderID: 10250, CustomerID: "Christina Berglund", constantType: true, otherFieldType: false, Freight: 65.83, OrderDate: '4/8/2019', ShipCountry: "Beligium" }
];;
. . . . . . .
var datePickerObj;
this.datepickerTemp = {
create: () => { debugger;
this.elem = document.createElement('input');
return this.elem;
},
destroy: () => {
this.datePickerObj.destroy();
},
read: () => {
return this.datePickerObj.value;
},
write: (args) => {
this.datePickerObj = new DatePicker({
value: new Date(args.rowData[args.column.field]),
format : 'dd/MM/yyyy' // Editing view
});
this.datePickerObj.appendTo(this.elem);
}
};
}
actionBegin(args) {
if (args.requestType === "save") {
let intl = new Internationalization();
args.data.OrderDate = intl.formatDate(args.data.OrderDate, { format: "MM/dd/yyyy" })
console.log(args.data);
}
}
render() {
return (
<GridComponent
dataSource={this.data}
actionBegin={this.actionBegin.bind(this)}
. . . . .
>
<ColumnsDirective>
. . . . .
<ColumnDirective
field="OrderDate"
headerText="Order Date"
type='date'
format='dd/MM/yyyy' // Initial view
edit={this.datepickerTemp}
width="160"
/>
. . .
</ColumnsDirective>
<Inject services={[Page, Toolbar, Edit]} />
</GridComponent>
</div>
</div>
</div>
);
}
} |