i have jqgrid and a modal. By using the modal window we can add value to the grid
at the same time while editing on row of the grid the modal window has to be shown and populate with the row value from grid. i have tried the #htmlaction click on the jqgrid it goes to the controller it ok but how can call the modal window to populate the grid row data while on editing.
jQuery("#listvalues_ajaxGrid").jqGrid({
url: '#Url.Action("ListvaluesGrid")',
datatype: "json",
mtype: 'Get',
colNames: [
'List Key', 'List Value Name', 'List Value Code', 'Inactive'],
colModel: [
{ key: false, name: 'list_key', hidden: true },
{
key: false, name: 'list_value_name',
formatter: function (cellvalue, options, rowObject) {
show();
var x = '#Html.ActionLink("Col", "Edit", "Lists", new { id = "listvalid" }, new { #style = "color:black;font-weight:bold;" })';
return x.replace("listvalid", rowObject.list_key).replace("Col", rowObject.list_value_name);
}, sortable: true, align: 'left', width: 200, editable: true
},
#*#Html.ActionLink("Edit", "Edit", null, new { id = 234 }, new { #class = "modal" })*#
//{ key: true, name: 'list_value_name', hidden: false, editable:true },
{ key: false, name: 'list_value_code', hidden: false, editable: false },
{ key: false, name: 'inactive', hidden: false, width: 50, sortable: false, formatter: "checkbox", align: "center", editable: false },
],
sortname: 'list_key',
sortorder: "asc",
viewrecords: true,
rowNum: 5,
pager: '#listvalues_ajaxPager',
onSelectRow: function (id) {
if (id && id !== lastSel) {
listvalues_ajaxGrid.jqGrid('restoreRow', lastSel);
var cm = grid.jqGrid('getColProp', 'Name');
cm.editable = false;
grid.jqGrid('editRow', id, true, null, null, 'clientArray');
cm.editable = true;
lastSel = id;
}
},
height: '200px', mtype: 'GET',
emptyrecords: 'No records found',
autowidth: true,
mutiselect: true,
altRows: true,
'cellEdit': true,
'cellsubmit': 'clientArray',
editurl: '#Url.Action("ListvaluesGrid")',
loadComplete: function () {
var table = this;
setTimeout(function () {
updatePagerIcons(table);
}, 0);
},
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
userdata: "userdata"
},
//editurl:
});
my bootstrap modal window
<div class="modal fade" id="modalBootstrap" role="dialog">
#Html.Hidden("hid_listvalues")
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">List Values</h4>
</div>
<div class="modal-body">
<div class="form-group">
#Html.LabelFor(model => model.maslistvalues.list_value_code, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.maslistvalues.list_value_code, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.maslistvalues.list_value_code, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.maslistvalues.list_value_name, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.maslistvalues.list_value_name, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.maslistvalues.list_value_name, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.maslistvalues.inactive, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
<div class="checkbox">
#Html.EditorFor(model => model.maslistvalues.inactive)
#Html.ValidationMessageFor(model => model.maslistvalues.inactive, "", new { #class = "text-danger" })
</div>
</div>
</div>
</div>
<div class="modal-footer">
<div class="wizard-actions">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<input type="submit" value="Save" class="btn btn-primary" onclick="saveclick_listvalues();" />
</div>
</div>
</div>
</div>
</div>
In the jquery formatter function we can call the modal popup
formatter: function (cellvalue, options, rowObject) {
var x ='#Html.ActionLink("Col", "Index", "Lists", new { id1 = "listid" }, new { #style = "color:black;font-weight:bold;", onclick="check();" })';
//var x+='<i class="fa fa-pencil icon"></i>';
var a = sessionStorage["Selected"];
if (a == 0)
{
$('#modalBootstrap').modal('show'); //---popupshow
sessionStorage["Selected"] = null;
}
return x.replace("listid", rowObject.list_value_key).replace("Col", rowObject.list_value_name);
}, sortable: false, align: 'left', editable: false
Related
I have a View from which a button call a dialog Bootstrap.
Inside this dialog I render this view:
#using (Ajax.BeginForm("Create", new { #class = "form-control", id="form-create" }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "wrapperViews" }))
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(false)
<hr />
<div class="form-horizontal">
<div id="divParamType" style="display: none;"></div>
<div class="form-group">
#Html.LabelFor(x => Model.PhaseID, htmlAttributes: new { #class = "control-label col-md-1" })
<div class="col-md-3">
#Html.DropDownListFor(x => Model.PhaseID,
new SelectList(Model.Phases, "Value", "Text"), "", new { #class = "form-control", id = "Phase" })
#Html.ValidationMessageFor(x => Model.PhaseID, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(x => Model.ParamID, "Description", htmlAttributes: new { #class = "control-label col-md-1" })
<div class="col-md-3">
#Html.DropDownListFor(x => Model.ParamID,
new SelectList(Model.ProcessIDListParams, "Value", "Text"), "", new { #class = "form-control", id = "ProcessParam" })
#Html.ValidationMessageFor(x => Model.ParamID, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group" id="forList">
#Html.LabelFor(x => Model.CodeValue, htmlAttributes: new { #class = "control-label col-md-1" })
<div class="col-md-3">
#Html.DropDownListFor(x => Model.CodeValue,
new SelectList(Model.PPvalues, "Value", "Text"), "", new { #class = "form-control", id = "PPValue" })
#Html.ValidationMessageFor(x => Model.CodeValue, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group" id="forOtherType">
#Html.LabelFor(x => Model.CodeValue, htmlAttributes: new { #class = "control-label col-md-1" })
<div class="col-md-2">
#Html.TextBoxFor(x => Model.CodeValue, new { #class = "form-control", id = "PPValTextBox" })
#Html.ValidationMessageFor(x => Model.CodeValue, "", new { #class = "text-danger" })
<div id="idTypeValue1"></div>
</div>
#Html.Label("<=", htmlAttributes: new { #class = "control-label col-md-1", id = "SecondValueLabel" })
<div class="col-md-2">
#Html.TextBoxFor(x => Model.SecondValue, new { #class = "form-control", id = "SecondValue" })
#Html.ValidationMessageFor(x => Model.SecondValue, "", new { #class = "text-danger" })
<div id="idTypeValue2"></div>
</div>
</div>
}
by calling #Html.Action("Create", "Search")
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h5 class="modal-title">Add Parameter</h5>
</div>
<div class="modal-body">
#Html.Action("Create", "Search")
<div id="myModalContent"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<input type="submit" id="bntSubmit" , name="name" class="btn btn-primary" value="Save" />
</div>
</div>
</div>
So far so good, my dialog opens and shows the view.
But when I click on Save button , my ajax request fails for I cannot pass the data even if I serialized the form. The form id is "form-create" on the View:
#using (Ajax.BeginForm("Create", new { #class = "form-control", id="form-create" }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "wrapperViews" }))
but when result from serialize() is empty.
$(document).ready(function () {
$('#bntSubmit').click(function (e) {
debugger;
e.preventDefault();
var form = $("#form-create").serialize();
debugger;
$.ajax({
type: "POST",
url: '/Search/Create',
data: form,
success: function () {
$('#myModal').modal("hide");
},
error: function () {
alert("Dynamic content load failed.");
}
});
});
});
I tried to change id form with modal id but nothing changed.
I am struggling over this for one day and no solution yet.
Any help would be appreciated.
First, make sure you include the "jquery.unobtrusive-ajax.min.js" in your layout, "Ajax.Beginform" won't work without it.
If that doesn't work, try just submit the form.
By using an "Ajax.Beginform", you should just bind :
$(function () {
$('#bntSubmit').on('click', function (e) {
e.preventDefault();
$('form-create').submit();
});
});
And use "OnSuccess" event in the "AjaxOptions" object to do the rest.
I want to load every year's data in jqgrid when I click on a button and after loading a modal form and selecting the year from drop down list. a diagram of the steps
but i don't know how to do this.
And this is my source code :
<!-- Page content -->
<div class="w3-content" style="max-width: 100%">
<div class="container" style="width:40%;margin-top:2%">
Filter
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
×
</div>
<div class="modal-body">
<form id="myForm" dir="rtl">
<div class="form-group">
<label>Year</label>
#Html.DropDownListFor(model => model.YEAR_ABBR, ViewBag.YearList as MultiSelectList, "--select--", new { #class = "form-control", #id = "ddlYear", multiple = "multiple" })
</div>
</form>
</div>
<div class="modal-footer">
Cancel
<input type="reset" value="GetRep" class="btn btn-success" id="btnSubmit" />
</div> </div>
</div> </div> </div>
<div dir="rtl" align="center" style="overflow:auto" class="tablecontainer">
<div id="rsperror"></div>
<table id="list" cellpadding="0" cellspacing="0"></table>
<div id="pager" style="text-align:center;"></div>
</div>
Now my script is something like this:
<script type="text/javascript">
$(document).ready(function () {
bindData();
$("#btnSubmit").click(function () {
$('#list').trigger('reloadGrid'); })
});
var bindData = function () {
$('#list').jqGrid({
url: '#Url.Action("Get_RepContracts","Home")',
postData: { YEAR_ABBR: function () { return $('#YEAR_ABBR').val(); } },
datatype: 'json',
jsonReader: {
root: "Rows",
page: "Page",
},
mtype: 'GET',
//columns names
colNames: ['Vahed_Descript' ],
colModel: [
{ name: 'Vahed_Descript', index: 'Vahed_Descript', align: 'right', width: 200, sorttype: "number", }
],
pager: $('#pager'),
rowNum: 800,
rowList: [ 800 ,1000],
sortname: 'Vahed_Descript',
hidegrid: false,
direction: "rtl",
gridview: true,
rownumbers: true,
footerrow: true,
userDataOnFooter: true,
loadComplete: function () {
calculateTotal();
$("tr.jqgrow:odd").css("background", "#E0E0E0");
},
loadError: function (xhr, st, err) {
jQuery("#rsperror").html("Type: " + st + "; Response: " + xhr.status + " " + xhr.statusText);
} , loadonce: true
}) ;
And here the button code ( My modal form works well. when I click the filter button, the filter options in my modal form appear, and then I select the year from year dropdownlist in modal and then i click the report button, after that the below code fires and I can see the selected year's data in action "Get_RepContracts" but it does not bind to my jqgrid):
Thanks in Advance...
UPDATE : Now My code is like below :
$(document).ready(function () {
bindData();
$("#btnSubmit").click(function () {
var myPostData = $('#list').jqGrid("getGridParam", "postData");
$('#list').trigger('reloadGrid');
$("#myModal").modal("hide");
}) });
var bindData = function () {
$('#list').jqGrid({
url: '#Url.Action("Get_RepContracts","Home")',
postData: {
YEAR_ABBR : function () { return $("#YEAR_ABBR").val();},
} ,
datatype: 'json',
jsonReader: { ........
It seems to me that you have small problem with the usage of correct id of select element. Your HTML code contains #id = "ddlYear" parameter of #Html.DropDownListFor:
#Html.DropDownListFor(
model => model.YEAR_ABBR,
ViewBag.YearList as MultiSelectList,
"--select--",
new {
#class = "form-control",
#id = "ddlYear",
multiple = "multiple"
}
)
but you still use
postData: {
YEAR_ABBR: function () { return $("#YEAR_ABBR").val(); }
}
To solve the problem you should just modify the code to
postData: {
YEAR_ABBR: function () { return $("#ddlYear").val(); }
}
I have implemented a code to create Tree View and also save it into database.
Controller
public ActionResult IndexMda()
{
using (BackendEntities context = new BackendEntities())
{
var plist = context.MDA.Where(p => p.PARENT_MDA_ID == null).Select(a => new
{
a.MDA_ID,
a.MDA_NAME,
a.MDA_DESCRIPTION,
a.ORGANIZATION_TYPE
}).ToList();
ViewBag.plist = plist;
}
GetHierarchy();
return View();
}
public JsonResult GetHierarchy()
{
List<MDA2> hdList;
List<MdaViewModel> records;
using (BackendEntities context = new BackendEntities())
{
hdList = context.MDA.ToList();
records = hdList.Where(l => l.PARENT_MDA_ID == null)
.Select(l => new MdaViewModel
{
MDA_ID = l.MDA_ID,
text = l.MDA_NAME,
MDA_DESCRIPTION = l.MDA_DESCRIPTION,
ORGANIZATION_TYPE = l.ORGANIZATION_TYPE,
PARENT_MDA_ID = l.PARENT_MDA_ID,
children = GetChildren(hdList, l.MDA_ID)
}).ToList();
}
return this.Json(records, JsonRequestBehavior.AllowGet);
// return View();
}
private List<MdaViewModel> GetChildren(List<MDA2> hdList, long PARENT_MDA_ID)
{
return hdList.Where(l => l.PARENT_MDA_ID == PARENT_MDA_ID)
.Select(l => new MdaViewModel
{
MDA_ID = l.MDA_ID,
text = l.MDA_NAME,
MDA_DESCRIPTION = l.MDA_DESCRIPTION,
ORGANIZATION_TYPE = l.ORGANIZATION_TYPE,
PARENT_MDA_ID = l.PARENT_MDA_ID,
children = GetChildren(hdList, l.MDA_ID)
}).ToList();
}
[HttpPost]
public JsonResult ChangeNodePosition(long MDA_ID, long PARENT_MDA_ID)
{
using (BackendEntities context = new BackendEntities())
{
var Hd = context.MDA.First(l => l.MDA_ID == MDA_ID);
Hd.PARENT_MDA_ID = PARENT_MDA_ID;
context.SaveChanges();
}
return this.Json(true, JsonRequestBehavior.AllowGet);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult AddNewNode(AddNode model)
{
try
{
if (ModelState.IsValid)
{
using (BackendEntities db = new BackendEntities())
{
MDA2 hierarchyDetail = new MDA2()
{
MDA_NAME = model.NodeName,
PARENT_MDA_ID = model.ParentName,
MDA_DESCRIPTION = model.NodeDescription,
ORGANIZATION_TYPE = model.NodeOrganizationType
};
db.MDA.Add(hierarchyDetail);
db.SaveChanges();
}
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}
}
catch (Exception ex)
{
throw ex;
}
return Json(new { success = false }, JsonRequestBehavior.AllowGet);
}
The partial view is where the Tree View is created
Partial View
#model BPP.CCSP.Admin.Web.ViewModels.AddNode
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button"
class="close"
data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Add Node</h4>
</div>
<div class="modal-body">
#using (Html.BeginForm("AddNewNode", "Mda", FormMethod.Post, new { #id = "formaddNode", #class = "form-horizontal", role = "form", enctype = "multipart/form-data" }))
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
<div class="col-md-12">
<div class="col-md-6 row">
<div class="input-group">
<input type="text" class="form-control" value="Perent Node" readonly="readonly">
<span class="input-group-addon">
#Html.RadioButtonFor(model => model.NodeTypeRbtn, "Pn", new { #class = "btn btn-primary rbtnnodetype" })
</span>
</div>
</div>
<div class="col-md-6">
<div class="input-group ">
<input type="text" class="form-control" value="Child Node" readonly="readonly">
<span class="input-group-addon">
#Html.RadioButtonFor(model => model.NodeTypeRbtn, "Cn", new { #class = "rbtnnodetype" })
</span>
</div>
</div>
<br />
#Html.ValidationMessageFor(m => m.NodeTypeRbtn, "", new { #class = "alert-error" })
</div>
<div class="clearfix">
</div>
<div class="col-md-12">
<div class="petenddiv hidden">
#Html.Label("Select Parent")
#Html.DropDownList("ParentName", new SelectList(ViewBag.plist, "MDA_ID", "MDA_NAME"), "--select--", new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.ParentName, "", new { #class = "alert-error" })
</div>
</div>
<div class="clearfix">
</div>
<div class="col-md-12">
<div>
#Html.Label("MDA Name")
#Html.TextBoxFor(model => model.NodeName, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.NodeName, "", new { #class = "alert-error" })
</div>
</div>
<div class="col-md-12">
<div>
#Html.Label("Description")
#Html.TextBoxFor(model => model.NodeDescription, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.NodeDescription, "", new { #class = "alert-error" })
</div>
</div>
<div class="col-md-12">
<div>
#Html.Label("Organization Type")
#Html.DropDownListFor(model => model.NodeOrganizationType, new List<SelectListItem>
{
new SelectListItem{Text = "Agency", Value = "Agency"},
new SelectListItem{Text = "Commission", Value = "Commission"},
new SelectListItem{Text = "Department", Value = "Department"},
new SelectListItem{Text = "Ministry", Value = "Ministry"}
}, "Select Error Type", new { #style = "border-radius:3px;", #type = "text", #class = "form-control", #placeholder = "Enter Organization Type", #autocomplete = "on" })
#Html.ValidationMessageFor(model => model.NodeDescription, "", new { #class = "alert-error" })
</div>
</div>
<div class="clearfix">
</div>
<br />
<br />
<div class="col-md-12">
<div>
<div class="pull-left">
<input type="submit" id="savenode" value="S A V E" class="btn btn-primary" />
</div>
<div class="pull-right">
<input type="button" id="closePopOver" value="C L O S E" class="btn btn-primary" />
</div>
</div>
</div>
<div class="clearfix">
</div>
}
</div>
</div>
View
<div class="col-md-12" style="margin:100px auto;">
<div class="modal fade in" id="modalAddNode" role="dialog" aria-hidden="true">
#Html.Partial("_AddNode")
</div>
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">Ministries, Departments and Agencies -: [ Add MDA and its Members ]</div>
<div class="panel-body">
<div id="tree"></div>
<div class="clearfix">
</div>
<br />
<div>
<button id="btnDeleteNode" data-toggle="modal" class='btn btn-danger'> Delete Node <span class="glyphicon glyphicon-trash"></span> </button>
<button id="btnpopoverAddNode" data-toggle="modal" class='btn btn-warning'> Add Node <span class="glyphicon glyphicon-plus"></span> </button>
</div>
</div>
</div>
</div>
Scipts
#section Scripts {
#System.Web.Optimization.Scripts.Render("~/bundles/jqueryval")
<script src="#Url.Content("~/Scripts/conditional-validation.js")" type="text/javascript"></script>
<script src="~/Scripts/Gijgo/gijgo.js"></script>
<link href="http://code.gijgo.com/1.3.0/css/gijgo.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
//'Hierarchy/GetHierarchy'
$(document).ready(function () {
var Usertree = "";
var tree = "";
$.ajax({
type: 'get',
dataType: 'json',
cache: false,
url: '/Mda/GetHierarchy',
success: function (records, textStatus, jqXHR) {
tree = $('#tree').tree({
primaryKey: 'MDA_ID',
dataSource: records,
dragAndDrop: true,
checkboxes: true,
iconsLibrary: 'glyphicons',
//uiLibrary: 'bootstrap'
});
Usertree = $('#Usertree').tree({
primaryKey: 'MDA_ID',
dataSource: records,
dragAndDrop: false,
checkboxes: true,
iconsLibrary: 'glyphicons',
//uiLibrary: 'bootstrap'
});
tree.on('nodeDrop', function (e, MDA_ID, PARENT_MDA_ID) {
currentNode = MDA_ID ? tree.getDataById(MDA_ID) : {};
console.log("current Node = " + currentNode);
parentNode = PerentId ? tree.getDataById(PARENT_MDA_ID) : {};
console.log("parent Node = " + parentNode);
if (currentNode.PARENT_MDA_ID === null && parentNode.PARENT_MDA_ID === null) {
alert("Parent node is not droppable..!!");
return false;
}
// console.log(parent.HierarchyLevel);
var params = { MDA_ID: MDA_ID, PARENT_MDA_ID: PARENT_MDA_ID };
$.ajax({
type: "POST",
url: "/Mda/ChangeNodePosition",
data: params,
dataType: "json",
success: function (data) {
$.ajax({
type: "Get",
url: "/Mda/GetHierarchy",
dataType: "json",
success: function (records) {
Usertree.destroy();
Usertree = $('#Usertree').tree({
primaryKey: 'MDA_ID',
dataSource: records,
dragAndDrop: false,
checkboxes: true,
iconsLibrary: 'glyphicons',
//uiLibrary: 'bootstrap'
});
}
});
}
});
});
$('#btnGetValue').click(function (e) {
var result = Usertree.getCheckedNodes();
if (result == "") { alert("Please Select Node..!!") }
else {
alert("Selected Node id is= " + result.join());
}
});
//delete node
$('#btnDeleteNode').click(function (e) {
e.preventDefault();
var result = tree.getCheckedNodes();
if (result != "") {
$.ajax({
type: "POST",
url: "/Mda/DeleteNode",
data: { values: result.toString() },
dataType: "json",
success: function (data) {
alert("Deleted successfully ");
window.location.reload();
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Error - ' + errorThrown);
},
});
}
else {
alert("Please select Node to delete..!!");
}
});
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Error - ' + errorThrown);
}
});
// show model popup to add new node in Tree
$('#btnpopoverAddNode').click(function (e) {
e.preventDefault();
$("#modalAddNode").modal("show");
});
//Save data from PopUp
$(document).on("click", "#savenode", function (event) {
event.preventDefault();
$.validator.unobtrusive.parse($('#formaddNode'));
$('#formaddNode').validate();
if ($('#formaddNode').valid()) {
var formdata = $('#formaddNode').serialize();
// alert(formdata);
$.ajax({
type: "POST",
url: "/Mda/AddNewNode",
dataType: "json",
data: formdata,
success: function (response) {
// $("#modalAddNode").modal("hide");
window.location.reload();
},
error: function (response) {
alert('Exception found');
// $("#modalAddNode").modal("hide");
window.location.reload();
},
complete: function () {
// $('.ajax-loader').css("visibility", "hidden");
}
});
}
});
//Close PopUp
$(document).on("click", "#closePopup", function (e) {
e.preventDefault();
$("#modalAddNode").modal("hide");
});
$('.rbtnnodetype').click(function (e) {
if ($(this).val() == "Pn") {
$('.petenddiv').attr("class", "petenddiv hidden");
$("#ParentName").val("");
}
else {
$('.petenddiv').attr("class", "petenddiv");
}
});
});
</script>
}
As shown above, what I have created can only do one level node. I want want to create multi-level.Whereby, a child will be a parent to other children.
Please how do I achieve this.
You can see some ASP.NET examples about this at https://github.com/atatanasov/gijgo-asp-net-examples/tree/master/Gijgo.Asp.NET.Examples
Please use our examples in order to achieve that.
I have my app MVC Asp.net using MVVM. I am trying to bind my grid to my ViewModel but it doesn't work. This is my sample:
My ViewModel ...
var CompanyViewModel = kendo.observable({
container: null,
tabGeneral_tbx_NamelId: "tabGeneral_tbx_Name",
tabGeneral_tbx_AddresslId: "tabGeneral_tbx_Address",
tabContactPerson_tbx_namelId: "tabContactPerson_tbx_name",
tabContactPerson_tbx_lastNamelId: "tabContactPerson_tbx_lastName",
tabContactPerson_tbx_phoneNumberlId: "tabContactPerson_tbx_phoneNumber",
tabContactPerson_tbx_workStationlId: "tabContactPerson_tbx_workStation",
tabContactPerson_tbx_emaillId: "tabContactPerson_tbx_email",
name: null,
address: null,
contactPerson_name: null,
contactPerson_lastName: null,
contactPerson_phoneNumber: null,
contactPerson_workStation: null,
contactPerson_email: null,
contactPersons: new kendo.data.DataSource(),
employees: [],
init: function (container) {
this.container = container;
kendo.bind(document.body.children, this);
this.createGridContactPersons();
//this.createTextBox();
this.bindKendoUIWidgets();
},
bindKendoUIWidgets: function () {
kendo.bind($("#grid_contactPerson"), this.contactPersons);
//kendo.bind($("#" + this.tabContactPerson_tbx_namelId), this.contactPerson_name);
},
createGridContactPersons: function () {
$("#grid_contactPerson").kendoGrid({
datasource: {
//data: new kendo.data.DataSource({ data: this.contactPersons }),
schema: {
model: {
fields: {
name: { type: "string" },
lastName: { type: "string" },
phoneNumber: { type: "string" },
workStation: { type: "string" },
email: { type: "string" }
}
}
}
},
autobind: true,
columns: [{
field: "name",
title: "Nombre",
width: 150
}, {
field: "lastName",
title: "Apellidos",
width: 270
}, {
field: "phoneNumber",
title: "Teléfono",
width: 160
}, {
field: "workStation",
title: "Puesto de Trabajo",
width: 270
}, {
field: "email",
title: "Email"
}]
});
},
createTextBox: function () {
$("#" + this.tabContactPerson_tbx_namelId).kendoText();
},
click_btnAddPersonContact: function (e) {
this.get("contactPersons").add({
name: this.get("contactPerson_name"),
lastName: this.get("contactPerson_lastName"),
phoneNumber: this.get("contactPerson_phoneNumber"),
workStation: this.get("contactPerson_workStation"),
email: this.get("contactPerson_email")
});
//this.get("contactPersons").push({
// name: this.get("contactPerson_name"),
// lastName: this.get("contactPerson_lastName"),
// phoneNumber: this.get("contactPerson_phoneNumber"),
// workStation: this.get("contactPerson_workStation"),
// email: this.get("contactPerson_email")
//});
//var grid = $("#grid_contactPerson").data("kendoGrid");
//grid.dataSource.data(this.contactPersons);
//grid.dataSource.fetch();
}
My View ...
section scripts
{
<script src="~/Content/js/Company.js"></script>
<script type="text/javascript">
$(document).ready(function () {
CompanyViewModel.init();
});
</script>
}
<div class="row">
<div class="form-group">
<label for="tabContactPerson_lbl_name" class="col-sm-4 control-label">Nombre</label>
<label for="tabContactPerson_lbl_lastName" class="col-sm-8 control-label">Apellidos</label>
</div>
<div class="form-group">
<div class="col-sm-4">
Html.Kendo().TextBox().Name("tabContactPerson_tbx_name").HtmlAttributes(new { #class = "form-control100", placeholder = "Nombre", data_bind = "value: contactPerson_name" })
</div>
<div class="col-sm-8">
Html.Kendo().TextBox().Name("tabContactPerson_tbx_lastName").HtmlAttributes(new { #class = "form-control", style = "width:100%", placeholder = "Apellidos", data_bind = "value: contactPerson_lastName" })
</div>
</div>
</div>
<br />
<div class="row">
<div class="form-group">
<label for="tabContactPerson_lbl_phoneNumber" class="col-sm-4 control-label">Teléfono</label>
<label for="tabContactPerson_lbl_workStation" class="col-sm-4 control-label">Puesto de Trabajo</label>
<label for="tabContactPerson_lbl_email" class="col-sm-4 control-label">E-mail</label>
</div>
<div class="form-group">
<div class="col-sm-4">
Html.Kendo().TextBox().Name("tabContactPerson_tbx_phoneNumber").HtmlAttributes(new { #class = "form-control", style = "width:100%", placeholder = "Teléfono", data_bind = "value: contactPerson_phoneNumber" })
</div>
<div class="col-sm-4">
Html.Kendo().TextBox().Name("tabContactPerson_tbx_workStation").HtmlAttributes(new { #class = "form-control", style = "width:100%", placeholder = "Puesto de Trabajo", data_bind = "value: contactPerson_workStation" })
</div>
<div class="col-sm-4">
Html.Kendo().TextBox().Name("tabContactPerson_tbx_email").HtmlAttributes(new { #class = "form-control", style = "width:100%", placeholder = "E-mail", data_bind = "value: contactPerson_email" })
</div>
</div>
</div>
<br />
<div class="row">
<div class="form-group">
<div class="col-sm-12">
<div id="grid_contactPerson"></div>
</div>
</div>
</div>
<br />
<div class="row">
<div class="form-group">
<div class="col-sm-2">
<input data-bind="events:{ click: click_btnAddPersonContact }" type="button" id="btnAddPersonContact" value="Agregar Persona de Contacto" />
</div>
</div>
</div>
When I AddPerson the grid does not update with the data from my DataSource. How can I bind my ViewModel to the data of the grid???
Thanks
I want to show a confirmation dialog and if user press 'continue', the form will be submit.
This is the jquery code:
$(document).ready(function () {
$('#submit').click(function () {
$('#confirmation-dialog').dialog('open');
return false; // prevents the default behaviour
});
$('#confirmation-dialog').dialog({
autoOpen: false, width: 400, resizable: false, modal: true, //Dialog options
buttons: {
"Continue": function () {
$(this).dialog('close');
var form = $('transferForm', this);
$(form).submit();
return true;
},
"Cancel": function () {
$(this).dialog("close");
return false;
}
}
});
});
And this is the form:
#using (Ajax.BeginForm("Transfer", "Location", null, new AjaxOptions
{
UpdateTargetId = "update-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
//OnBegin = "ajaxValidate",
OnSuccess = "updateSuccess"
}, new { #id = "transferForm" }))
{
<div style="width:600px;">
<div class="editorLabel">
#Html.LabelFor(m => m.FromEmail)
</div>
<div class="editorText">
#Html.TextBoxFor(m => m.FromEmail)
</div>
<div class="clear"></div>
<div class="editorLabel">
#Html.LabelFor(m => m.ToEmail)
</div>
<div class="editorText">
#Html.TextBoxFor(m => m.ToEmail)
</div>
<div class="clear"></div>
<p>
<input type="submit" name="submit" value="Transfer" class="btn" id="submit"/>
</p>
</div>
}
<div id="update-message"></div>
<div id="commonMessage"></div>
<div id="confirmation-dialog">
<p>Are you sure you want to proceed with transfer ?
</p>
</div>
But after the confirmation, the form is not submitted.
What could be wrong here?? any ideas??
Try changing this:
var form = $('transferForm', this);
$(form).submit();
to:
$("#IDofForm").submit();
as this inside the dialogs event handlers probably does'nt refer to what you think it does, and you probably don't have an element with a transferForm tagname (which is what you're targeting when not using # or . in front of the selector) ?