@Grid
@(Html.EJ().Grid<EmployeeView>("CustomGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource1)
.AllowPaging()
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.ExternalFormTemplate).ExternalFormTemplateID("#template"); })
.ClientSideEvents(e=>e.ActionComplete("complete"))
.Columns(col =>
{
col.Field("EmployeeID").HeaderText("Employee ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(100).Add();
col.HeaderText("Edit").Template("<input type='image' src ='../Content/icons/edit2.png' onclick='edit()' alt='Submit' width='48' height='48'>").Width(90).Add();
col.HeaderText("Delete").Template("<input type='image' src ='../Content/icons/delete.png' onclick='del()' alt='Submit' width='30' height='30'>").Width(80).Add();
})
) |
@Grid
@(Html.EJ().Grid<EmployeeView>("CustomGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource1)
.AllowPaging()
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.ExternalFormTemplate).ExternalFormTemplateID("#template"); })
.ClientSideEvents(e=>e.ActionComplete("complete"))
.Columns(col =>
{
col.Field("EmployeeID").HeaderText("Employee ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(100).Add();
col.HeaderText("Edit").Template("<input type='image' src ='../Content/icons/edit2.png' onclick='edit()' alt='Submit' width='48' height='48'>").Width(90).Add();
col.HeaderText("Delete").Template("<input type='image' src ='../Content/icons/delete.png' onclick='del()' alt='Submit' width='30' height='30'>").Width(80).Add();
})
)
@External template form
<script id="template" type="text/template">
<b>Order Details</b>
<table cellspacing="10">
<tr>
<td style="text-align: right;">
EmployeeID
</td>
<td style="text-align: left">
<input id="EmployeeID" name="EmployeeID" value="{{: EmployeeID}}" disabled="disabled" class="e-field e-ejinputtext valid e-disable"
style="text-align: right; width: 116px; height: 28px" />
</td>
<td style="text-align: right;">
FirstName
</td>
<td style="text-align: left">
<input id="FirstName" name="FirstName" value="{{: FirstName}}" class="e-field e-ejinputtext valid"
style="width: 116px; height: 28px" />
</td>
</tr>
<tr>
<td style="text-align: right;">
LastName
</td>
<td style="text-align: left">
<input type="text" id="LastName" name="LastName" value="{{:LastName}}" />
</td>
<td style="text-align: right;">
Country
</td>
<td style="text-align: left">
<select id="Country" name="Country">
<option value="USA">USA</option>
<option value="UK">UK</option>
<option value="Ireland">Ireland</option>
<option value="Italy">Italy</option>
<option value="Mexico">Mexico</option>
<option value="Norway">Norway</option>
<option value="Poland">Poland</option>
<option value="Portugal">Portugal</option>
<option value="Spain">Spain</option>
>
</select>
</td>
</tr>
<tr>
<td style="text-align: right;">
Hire Date
</td>
<td style="text-align: left">
<input id="HireDate" name="HireDate" value="{{: HireDate}}" class="e-field e-ejinputtext valid"
style="width: 116px; height: 28px" />
</td>
</tr>
</table>
</script> |
function edit() {
var gridInstance = $("#CustomGrid").ejGrid("instance");
gridInstance.startEdit(); //Start the edit action by calling the starEdit API
}
function del() {
var gridInstance = $("#CustomGrid").ejGrid("instance");
//here we can pass the Primary key field name and record to deleteRecord for deleting the record
gridInstance.deleteRecord("EmployeeID", gridInstance.getSelectedRecords()[0])
} |
@(Html.EJ().Grid<EmployeeView>("CustomGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource1)
.AllowPaging()
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.ExternalFormTemplate).ExternalFormTemplateID("#template"); })
.ClientSideEvents(e=>e.ActionComplete("complete"))
.Columns(col =>
{
. . .
})
)
@Complete event
function complete(args) {
if ((args.requestType == "beginedit" || args.requestType == "add") && args.model.editSettings.editMode == "externalformtemplate") {
$("#HireDate").ejDatePicker({ value: ($("#HireDate").val()), width: "116px", height: "28px", }); //render the date picker control
$("#Country").ejDropDownList({ width: '116px' }); //render the Dropdown list control
if (args.requestType == "beginedit") {
$("#Country").ejDropDownList("setSelectedValue", args.row.children().eq(4).text()); //set the Drodpown value for corresponding edited record
}
$(".e-field").css({ 'width': '116px', 'text-align': 'left' });
}
} |
I am amazed by your step by step answer. Thank you so much. I will try it and if I have any tricky problems I will be back here bothering you guys again.
Thank you