<appSettings>
....
<add key="UnobtrusiveJavaScriptEnabled" value="false" />
</appSettings>
@(Html.EJ().Grid<BusinessEntities.CompanyEntity>("CompanyGrid")
......
.EditSettings(edit => {
edit
.AllowAdding()
.AllowEditing()
.AllowDeleting()
.EditMode(EditMode.DialogTemplate)
.AllowEditOnDblClick(false)
.DialogEditorTemplateID("BranchesGridContent");
//.DialogEditorTemplateID("#BranchesGridContent");
}
......
.ClientSideEvents(events =>
{
events.ActionComplete("actionComplete");
events.ActionBegin("actionBegin");
})
)
<script type="text/javascript">
...
function actionComplete(args) {
var type = args.requestType;
if (type == "beginedit" || type == "add") {
if (!ej.isNullOrUndefined(args.rowIndex))
var Id = this.model.currentViewData[args.rowIndex]["Id"];
this.element.ejWaitingPopup("show");
$.ajax({
url: "/Company/CompanyEditPartial" + (type == "add" ? "" : "?companyId=" + Id),
type: 'GET',
success: ej.proxy(function (data) {
var div = ej.buildTag("div");
$("#" + this._id + "EditForm").prepend($(div).html(data));
//$("#" + this._id + "EditForm").html(data);
if (type != "add") $("#Id").addClass("e-disable").attr("disabled", "disabled");
this.element.ejWaitingPopup("hide");
ej.widget.init($("#" + this._id + "EditForm"))
//ej.widget.init($("#BranchesGridContent"))
//ej.widget.init($("#" + this._id + "EditForm"))
}, this),
error: ej.proxy(function (a, b, c, d) {
alert("error happened");
})
});
}
.....
}
</script>
[HomeController.cs]
[HttpGet]
public ActionResult CompanyEditPartial(long companyId)
{
var company = _companyService.GetById(companyId, true);
ViewBag.Branches = company.Branches;
return PartialView("_CompanyEdit", company);
}
[_CompanyEdit.cshtml] (partial view, the grid below never gets rendered, although accompanying html does)
<div id="BranchesGridContent">
<div>TEST HTML SHOWING THIS COMES FROM THE PARTIAL VIEW<div>
........
@(Html.EJ().Grid<BusinessEntities.BranchEntity>("CompanyBranches")
.Datasource((List<BusinessEntities.BranchEntity>)ViewBag.Branches)
.Data
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Search);
});
}
)
.EditSettings(edit =>
{
edit
.AllowAdding()
.AllowEditing()
.AllowDeleting();
//.EditMode(EditMode.DialogTemplate)
//.AllowEditOnDblClick(false)
//.DialogEditorTemplateID("CompanyEditTemplate");
}
)
.Columns(col =>
{
col.Field(p => p.Id).HeaderText("Company Id").IsPrimaryKey(true).Width(75).Add();
col.Field(p => p.Name).HeaderText("Name").Width(100).Add();
col.Field(p => p.Address).HeaderText("Address").Width(150).Add();
col.Field(p => p.City).HeaderText("City").Width(50).Add();
col.Field(p => p.State).HeaderText("State").Width(25).Add();
col.Field(p => p.Zip).HeaderText("Zip").Width(50).Add();
} )
)
</div>
@Html.EJ().ScriptManager()
I have included a zip file with the important files included (plus an image showing the end result).
Please advice on how to get this to work.
Thanks,
Fausto
|
<style>
.e-grid .e-dialog .gridform .e-rowcell {
padding: .5em;
}
</style>
|
|
<script>
function actionComplete(args) {
if (type == "beginedit" || type == "add") {
---
$.ajax
({
url: type == "add" ? "/Grid/EditPartial" : "/Grid/EditPartial?OrderID=" + OrderID,
type: 'GET',
success: ej.proxy(function (data) {
----
var obj = $("#Edit_dialogEdit").ejDialog('instance'); // Edit_dialogEdit is id of the dialogTemplate
obj.option({ width: 700, height: 600 });
}, this)
});
}
</script>
|