<ej:Grid ID="Grid" runat="server" AllowPaging="true">
. . .
<DataManager Adaptor="WebApiAdaptor" URL="/api/Orders" Offline="true" />
<Columns>
<ej:Column Field="OrderID" HeaderText="OrderID" IsPrimaryKey="true" />
<ej:Column Field="EmployeeID" HeaderText="Employee ID">
<EditTemplate Create="create" Read="read" Write="write" />
<%--render dropdown and datasource using the editTemplate--%>
</ej:Column>
. . .
</Columns>
<ClientSideEvents DataBound="dataBound" />
</ej:Grid>
<script type="text/javascript">
function dataBound(args) {
var data = new ej.DataManager({
url: "/api/Employees", adaptor: new ej.WebApiAdaptor(), offline: true
})
this.element.ejWaitingPopup("show");//show popup
data.executeQuery(new ej.Query())
.done(function (e) {
var obj = $('#<%= Grid.ClientID %>').ejGrid('instance');
obj.element.ejWaitingPopup("hide");//hide after loading data for dropdown
obj.getColumnByField("EmployeeID").dataSource = e.result
})
}
function create() {
return $("<input>");
}
function write(args) {
var obj = $('#<%= Grid.ClientID %>').ejGrid('instance');
args.element.ejDropDownList({
width: "100%",
dataSource: ej.distinct(obj.getColumnByField("EmployeeID").dataSource, "EmployeeID"),
value: args.rowdata !== undefined ? args.rowdata["EmployeeID"] : ""
});
}
function read(args) {
return args.ejDropDownList("getValue");
}
</script> |