import { extend } from '@syncfusion/ej2-base';
import { Grid, Edit, Toolbar, Page, Column, DropDownEditCell, NumericEditCell,
DefaultEditCell, BooleanEditCell, DatePickerEditCell} from '@syncfusion/ej2-grids'; |
let editCellType: Object = {
'dropdownedit': DropDownEditCell, 'numericedit': NumericEditCell,
'datepickeredit': DatePickerEditCell, 'booleanedit': BooleanEditCell, 'defaultedit': DefaultEditCell
}; |
let grid: Grid = new Grid(
{
dataSource: orderData,
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' },
allowPaging: true,
actionBegin: actionBegin,
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
columns: [
{
field: 'OrderID', isPrimaryKey: true, headerText: 'Order ID', textAlign: 'Right',
validationRules: { required: true }, width: 120
},
. . .
}],
});
grid.appendTo('#Grid');
function actionBegin(args: any): void{
if(args.requestType === 'beginEdit'){
let col : Column = this.getColumnByField('CustomerID');
if(args.rowData['CustomerID'] === 'VINET') {
col.editType = 'dropdownedit';
setEditType(col, this)
}
else {
col.editType = 'defaultedit';
setEditType(col, this)
}
}
}
function setEditType(gCol : Column, gridObj : Grid): void{
gCol.edit = extend(
new editCellType[gCol.editType && editCellType[gCol.editType] ?
gCol.editType : 'defaultedit'](gridObj, gridObj.serviceLocator),
gCol.edit || {}
} |
<ej:Grid ID="ProjectAttsGrid" runat='server' AllowFiltering="True" AllowPaging="True" AllowSorting="True" AllowResizing="true"
CssClass="" MinWidth="0">
. . .
<ClientSideEvents ToolbarClick="onToolBarClick" DataBound="bound" ActionBegin="actionBegin" />
<SelectionSettings EnableToggle="true" />
. . .
function bound(args) {
var col = this.getColumnByField('CustomerID');
if (col.type == 'string') {
col.editType = 'dropdownedit';
}
else {
col.editType = 'stringedit';
}
this.columns(args.model.columns);
}
|
<ClientSideEvents ToolbarClick="onToolBarClick" DataBound="bound" ActionBegin="actionBegin" ActionComplete="complete" />
.
.
.
var items = [{ text: "ListItem 1", value: "item1" },
{ text: "ListItem 2", value: "item2" },
{ text: "ListItem 3", value: "item3" },
{ text: "ListItem 4", value: "item4" },
{ text: "ListItem 5", value: "item5" }];
function complete(args) {
if (args.requestType == "beginedit") {
// MainContent _ "gridID+ " columnName
$("#MainContent_ProjectSettings_ProjectAttsGridCustomerID").ejDropDownList({
dataSource: items,
fields: { text: "text", value: "value" }
})
}
} |
|
let itemElem: HTMLElement;
let itemObj: DropDownList;
let items: { [key: string]: Object }[] = [
{ text: "France", value: "item1" },
{ text: "Germany", value: "item2" },
{ text: "Brazil", value: "item3" },
{ text: "Belgium", value: "item4" },
{ text: "Switzerland", value: "item5" }];
let grid: Grid = new Grid(
{
dataSource: orderDataSource,
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' },
allowPaging: true,
pageSettings: { pageSize: 6, pageCount: 5 },
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
columns: [
. . .
. . .
{
field: 'ShipCountry', headerText: 'Ship Country',width: 160, edit:{
create: () => {
itemElem = document.createElement('input');
return itemElem;
},
read: () => {
return itemObj.text;
},
destroy:() =>{
itemObj.text;
},
write: (e) => {
var Data = e.rowData.ShipCountry;
itemObj = new DropDownList({
dataSource: items,
fields : { value:'value' , text :'text'},
text: Data ,
floatLabelType: 'Never'
});
itemObj.appendTo(itemElem);
}
}
],
});
grid.appendTo('#Grid'); |