<script type="text/javascript">
<!--
$(document).ready(function () {
$('#btnGridview').click(function () {
var grid = $("#Grid").data("kendoGrid");
grid.dataSource.read();
grid.refresh();
HideProgressDialog();
});
});
//-->
</script>
@using (Html.BeginForm("IndexAjax", "Vendor"))
{
<button class="green" type="button" id="btnGridview" name="btnGridview">
<span>Gridview</span>
</button>
}
i want that this below code will run only when i click on gridview button.
i want to add this action on javascript .Read(read => read.Action("IndexAjax", "Vendor").Data("PassSearchParameter")).
because i want to load this grid only after button click. i do not want to initialize this grid for the first time.
@(Html.Kendo().Grid<Vendor>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(c => c.DisplayId).Title("<input type='checkbox' name='chkAllVendorId' id='chkAllVendorId' />").Width("10px").Sortable(false).Groupable(false).Filterable(false).ClientTemplate("<input type='checkbox' name='chkVendorId' value='#= VendorID #' id='#= VendorID #' />");
columns.Bound(c => c.DisplayId).Title("Display ID").Width("5%").Sortable(true).Groupable(false).Filterable(false).ClientTemplate("<a name='lnkOverview' id='lnkOverview_#= VendorID #' href='/VMS/Vendor/Dashboard?vendorId=#= VendorID #' target='_blank' title='Overview'>#= DisplayId #</a>");
columns.Bound(c => c.Name).Title("Vendor Name").Width("20%").Sortable(true).Groupable(true).Filterable(true);
columns.Bound(c => c.IndustryName).Title("Industry Category").Width("20%").Sortable(true).Groupable(true).Filterable(true);
columns.Bound(c => c.City).Title("City").Width("10%").Sortable(true).Groupable(true).Filterable(true);
columns.Bound(c => c.StateName).Title("State").Width("10%").Sortable(true).Groupable(true).Filterable(true);
columns.Bound(c => c.CountryName).Title("Country").Width("10%").Sortable(true).Groupable(true).Filterable(true);
columns.Bound(c => c.EmailAddress).Title("Vendor Email Address").Width("20%").Sortable(true).Groupable(true).Filterable(true);
columns.Bound(c => c.VendorStatusCategoryName).Title("Vendor Status Category").Width("10%").Sortable(true).Groupable(true).Filterable(true);
columns.Bound(p => p.FancyBoxLink).ClientTemplate("<a name='lnkViewer' id='lnkViewer_#= VendorID #' rev='/VMS/Vendor/DetailsAjax/#= VendorID #' class='popups' href='#= FancyBoxLink #' title='Details'><img alt='Details' src='/content/images/details.jpg' /></a> <a name='lnkEditor' id='lnkEditor_#= VendorID #' rev='/VMS/Vendor/EditorAjax/#= VendorID #' class='popups' href='#= FancyBoxLink #' title='Edit'><img alt='Edit' src='/content/images/edit.png' /></a> <a name='lnkDelete' id='lnkDelete_#= VendorID #' href='/VMS/Vendor/DeleteAjax/#= VendorID #' title='Delete'><img alt='Delete' src='/content/images/delete.png' /></a> <a name='lnkVerify' id='lnkVerify_#= VendorID #' rev='/VMS/Vendor/VerificationAjax/#= VendorID #' class='popups' href='#= FancyBoxLink #' title='Verify'><img alt='Verify' src='/content/images/#= IsVerified #.png' /></a>").Width("10%").HtmlAttributes(new { @class = "grid-actions-content" }).HeaderTemplate("<center>Actions</center>").HeaderHtmlAttributes(new { @class = "grid-actions-content" });
})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("IndexAjax", "Vendor").Data("PassSearchParameter"))
.PageSize(50)
)
.Pageable()
.Sortable()
)
@(Html.Kendo().TreeView() .Name("CategoryTreeView") .Events(e=>e.DataBound("onDataBound")) .Checkboxes(true) .DataTextField("Name") .DataSource(dataSource => dataSource .Read(read => read .Action("CategoryLoadNodes","Category") ) ) )public JsonResult CategoryLoadNodes(int? id) { IList<Category> categoryList = null; if (id.HasValue) { categoryList = CachedCategoryOnDemand().ChildCategoryList; } else { categoryList = CachedCategoryOnDemand().ParentCategoryList; } var nodes = from item in categoryList.Where(s=> id.HasValue ? s.ParentCategoryID == id : s.ParentCategoryID == null) select new { id = item.CategoryID, Name = item.CategoryDetails.FirstOrDefault().Name, hasChildren = item.CategoryChild.Any() }; return Json(nodes, JsonRequestBehavior.AllowGet); }<style> .k-group .k-top, .k-group .k-mid, .k-group .k-bot { background-image: url('http://aspnet-skins.telerikstatic.com/mvc/2012.2.607/Default/treeview-nodes.png'); } .k-group .k-item { background-image: url('http://aspnet-skins.telerikstatic.com/mvc/2012.2.607/Default/treeview-line.png'); } .k-group .k-last { background-image: none; } .k-group .k-top, .k-group .k-mid, .k-group .k-bot { background-repeat: no-repeat; margin-left: -16px; padding-left: 16px; } .k-group .k-top { background-position: -91px 0; } .k-group .k-bot { background-position: -69px -22px; } .k-group .k-mid { background-position: -47px -44px; } .k-group .k-last .k-top { background-position: -25px -66px; } .k-group .k-group .k-last .k-bot { background-position: -69px -22px; } .k-group .k-item { background-repeat: no-repeat; } .k-group .k-first { background-repeat: no-repeat; background-position: 0 16px; } </style><script type="text/javascript"> function onDataBound() { $("input:checkbox[name=checkedNodes]").on('click', function () { var catDesc = ''; var catId = 0; if ($(this).is(':checked')) { catId = $(this).attr('value'); $(this).parent().siblings().each(function () { var text = $(this).text(); if (text && text != undefined) { catDesc = text.replace(/&/g, '&'); return false; } }); //uncheck all checked checkboxes $("input:checked[name=checkedNodes]").each(function () { $(this).attr('checked', false); }); //recheck this $(this).attr('checked', true); } $('#CategoryID').val(catId); $('#CategoryName').val(catDesc); }); } </script>int cnt = -1;@(Html.Kendo().TreeView() .Name("LastYearSalesTreeView") .Checkboxes(true) .Items(treeview => { bool expandParent = true; treeview.Add().Text("Annual Sales").Id("-1") .Expanded(expandParent) .Items(item => { foreach (AnnualSalesRange annualSalesRange in Model.SearchSaveModel.FilteredAnnualSalesRangeList) { cnt++; //String annualSalesText = @String.Format("{0} ({1})", Model.FilteredAnnualSalesRangeList[cnt].AnnualSalesRangeName, Model.FilteredAnnualSalesRangeList[cnt].AnnualSalesRangeCount); String annualSalesText = Model.SearchSaveModel.FilteredAnnualSalesRangeList[cnt].AnnualSalesRangeName; item.Add().Text(annualSalesText) .Checked(Model.SearchSaveModel.FilteredAnnualSalesRangeList[cnt].AnnualSalesRangeChecked) .Id(Model.SearchSaveModel.FilteredAnnualSalesRangeList[cnt].AnnualSalesRangeID.ToString()); } }); }) ) @Html.Hidden("LastYearSalesCheckedStates");treeview.Add().Text("Annual Sales").Id("-1")@Html.Hidden("LastYearSalesCheckedStates");<script type="text/javascript"> function LastYearSalesCheckedState() { this.AnnualSalesRangeID = ''; this.IsChecked = false; }; var LastYearSalesCheckedStates = []; $(document).ready(function () { $("#LastYearSalesTreeView input:checkbox[name=checkedNodes]").on('click', function () { showButtonforLastYearSalesChecked(); var rangeID = $(this).attr('value'); // find the corresponding rangeID in the array var rangeIDs = $.grep(LastYearSalesCheckedStates, function (n, i) { return n.AnnualSalesRangeID == rangeID; }); if (rangeIDs.length > 0) { var LastYearSalesChecked = rangeIDs[0]; if ($(this).is(':checked')) { LastYearSalesChecked.IsChecked = true; } else { LastYearSalesChecked.IsChecked = false; } } else { var LastYearSalesChecked = new LastYearSalesCheckedState(); LastYearSalesChecked.AnnualSalesRangeID = $(this).attr('value'); if ($(this).is(':checked')) { LastYearSalesChecked.IsChecked = true; } else { LastYearSalesChecked.IsChecked = false; } LastYearSalesCheckedStates.push(LastYearSalesChecked); } var jsonData = JSON.stringify(LastYearSalesCheckedStates); $("#LastYearSalesCheckedStates").val(jsonData); }); $("#LastYearSalesTreeView input:checkbox[name=checkedNodes]").each(function () { if ($(this).attr('value') < 0) { //hide the check box, mimics checkable(false) $(this).hide() } }); //populate the array with checked items $("#LastYearSalesTreeView input:checked[name=checkedNodes]").each(function () { var LastYearSalesChecked = new LastYearSalesCheckedState(); LastYearSalesChecked.AnnualSalesRangeID = $(this).attr('value'); if ($(this).is(':checked')) { LastYearSalesChecked.IsChecked = true; } else { LastYearSalesChecked.IsChecked = false; } LastYearSalesCheckedStates.push(LastYearSalesChecked); }); });</script>The LastYearSalesCheckedStates array is JSON stringified and assigned to the hidden field.
There is a separate submit button for each treeview, which posts the whole form. It changes the form's action prior to posting so that a different action on the controller can manage each of the treeviews
Here is an abridged version of my controller Action
[HttpPost]//public ActionResult FilteredLastYearSales(SearchModel model, List<TreeViewItem> LastYearSalesTreeView_checkedNodes)// public ActionResult FilteredLastYearSales(SearchModel model, int[] checkedNodes) public ActionResult FilteredLastYearSales(SearchModel model) { List<LastYearSalesCheckedState> LastYearSalesCheckedStateList = null; if (Request.Form["LastYearSalesCheckedStates"] != null) { LastYearSalesCheckedStateList = CommonTools.DeSerializeJsonObject<List<LastYearSalesCheckedState>>(Request.Form["LastYearSalesCheckedStates"]); }public class LastYearSalesCheckedState { public String AnnualSalesRangeID { get; set; } public bool IsChecked { get; set; } }using System.Web.Script.Serialization; public static T DeSerializeJsonObject<T>(String strJSON) where T : class { JavaScriptSerializer ser = new JavaScriptSerializer(); return ser.Deserialize<T>(strJSON) as T; }@model IEnumerable<HCS.Model.FinancialInstitution>@(Html.Kendo().Grid(Model) .Name("Grid") .Columns(columns => { columns.Bound(p => p.ID).Visible(false); columns.Bound(p => p.MainRT).Groupable(false); columns.Bound(p => p.LegalName); }) .Sortable() .Scrollable() .Filterable() .Selectable() .DataSource(dataSource => dataSource .Ajax() .ServerOperation(false)) )Unhandled exception at line 8, column 374994 in http://localhost:3407/Scripts/KendoUI/kendo.web.min.js
0x800a138f - Microsoft JScript runtime error: 'f[...].uid' is null or not an object
@
using DnB.Connect.Mvc.Common.BaseTypes;
@
using DnB.ConnectEntityModel;
@model DnB.Connect.Mvc.Common.BaseTypes.
CategoryEdit
<
script type="text/javascript">
function nodeChecked(e) {
//remember whether e is checked
var isChecked = e.checked;
//select all items
var allCheckboxes = $('#CategoryTreeView').find("li").find('> div > .t-checkbox :checkbox:checked')
//alert('after find');
//remove all checks
$.each(allCheckboxes,
function (index, checkbox) {
$(checkbox).attr(
'checked', false);
});
//alert('after check removal');
//put e back as you found it
e.checked = isChecked;
var catDesc = '';
var catId = 0;
if (isChecked) {
catDesc = $($(e.item)[0]).find(
'span.t-in')[0].innerHTML;
catDesc = catDesc.replace(
/&/g, '&');
catId = $($(e.item)[0]).find(
'input[name="itemValue"]')[0].value;
$(
'#CategoryID').val(catId);
$(
'#CategoryName').val(catDesc);
}
var span = $("#CatError").remove();
}
</
script>
<
div id="catTreeModal" class="reveal-modal">
<h3>Select Category</h3>
<a class="small nice blue radius button bump close-reveal-modal">Done</a>
@*
@(Html.Telerik().TreeView().Name("CategoryTreeView")
.ShowCheckBox(true)
.ShowLines(true)
.ClientEvents(e => e.OnChecked("nodeChecked"))
.BindTo(@Model.CategoryList, (item, cat) =>
{
item.Text = cat.CategoryDetails.FirstOrDefault().Name;
item. Value = cat.CategoryID.ToString();
item.LoadOnDemand = cat.CategoryChild.Any();
})
.DataBinding(dataBinding => dataBinding
.Ajax().Select("CategoryLoadChildren", "Base"))
)
*@
@(Html.Kendo().TreeView()
.Name(
"CategoryTreeView") //The name of the treeview is mandatory. It specifies the "id" attribute of the widget.
.Events(e => e.Select(
"nodeChecked"))
.BindTo(@Model.CategoryList, mapping => mapping
.For<
Category>(binding => binding
.Children(c => c.CategoryChild)
.ItemDataBound((item, c) => item.Text = c.CategoryDetails.FirstOrDefault().Name)
)
)
.DataSource(source => {
source.Read(read =>
{
read.Action(
"CategoryLoadChildren", "Base");
});
})
.CheckboxTemplate(
"<input type='checkbox' />")
)
</
div>
 
 
<
script id="itemInfoTemplate" type="text/kendo-ui-template">
# var name = "checkedCategory"; /* modify this to change the argument name */ #
# var arrayItem = name + "[" + index + "]"; #
<input type="hidden" name="#= name #.Index" value="#= index #" />
<input type="hidden" name="#= arrayItem #.Id" value="#= item.id #" />
<input type="hidden" name="#= arrayItem #.Name" value="#= item.Name #" />
</
script>
<
script type="text/javascript">
function getNodeIndex(node) {
return node.parentsUntil(".k-treeview", ".k-item").map(function () {
return $(this).index();
}).toArray().reverse().join(
":");
}
$(document).ready(
function () {
var itemInfoTemplate = kendo.template($("#itemInfoTemplate").html());
var treeview = $("#CategoryTreeView");
treeview.on(
"change", ":checkbox", function (e) {
var checkbox = $(this),
dataItem = treeview.data(
"kendoTreeView").dataItem(checkbox.closest(".k-item")),
index = getNodeIndex(checkbox);
checkbox.nextAll().remove();
if (checkbox.is(":checked")) {
checkbox.after(itemInfoTemplate({
item: dataItem,
index: index
}));
}
});
});
 
 
</
script>
@using DnB.Connect.Mvc.Common.BaseTypes; @using DnB.ConnectEntityModel; @model DnB.Connect.Mvc.Common.BaseTypes.CategoryEdit <script type="text/javascript"> function nodeChecked(e) { //remember whether e is checked var isChecked = e.checked; //select all items var allCheckboxes = $('#CategoryTreeView').find("li").find('> div > .t-checkbox :checkbox:checked') //alert('after find'); //remove all checks $.each(allCheckboxes, function (index, checkbox) { $(checkbox).attr('checked', false); }); //alert('after check removal'); //put e back as you found it e.checked = isChecked; var catDesc = ''; var catId = 0; if (isChecked) { catDesc = $($(e.item)[0]).find('span.t-in')[0].innerHTML; catDesc = catDesc.replace(/&/g, '&'); catId = $($(e.item)[0]).find('input[name="itemValue"]')[0].value; $('#CategoryID').val(catId); $('#CategoryName').val(catDesc); } var span = $("#CatError").remove(); } </script> <div id="catTreeModal" class="reveal-modal"> <h3>Select Category</h3> <a class="small nice blue radius button bump close-reveal-modal">Done</a> @*@(Html.Telerik().TreeView().Name("CategoryTreeView") .ShowCheckBox(true) .ShowLines(true) .ClientEvents(e => e.OnChecked("nodeChecked")) .BindTo(@Model.CategoryList, (item, cat) => { item.Text = cat.CategoryDetails.FirstOrDefault().Name; item. Value = cat.CategoryID.ToString(); item.LoadOnDemand = cat.CategoryChild.Any(); }) .DataBinding(dataBinding => dataBinding .Ajax().Select("CategoryLoadChildren", "Base")) )*@ @(Html.Kendo().TreeView() .Name("CategoryTreeView") .Events(e => e.Select("nodeChecked")) .BindTo(@Model.CategoryList, mapping => mapping .For<Category>(binding => binding .Children(c => c.CategoryChild) .ItemDataBound((item, c) => item.Text = c.CategoryDetails.FirstOrDefault().Name) ) ) .DataSource(source => { source.Read(read => { read.Action("CategoryLoadChildren", "Base"); }); }) .CheckboxTemplate("<input type='checkbox' />") ) </div> <script id="itemInfoTemplate" type="text/kendo-ui-template"> # var name = "checkedCategory"; /* modify this to change the argument name */ # # var arrayItem = name + "[" + index + "]"; # <input type="hidden" name="#= name #.Index" value="#= index #" /> <input type="hidden" name="#= arrayItem #.Id" value="#= item.id #" /> <input type="hidden" name="#= arrayItem #.Name" value="#= item.Name #" /> </script> <script type="text/javascript"> function getNodeIndex(node) { return node.parentsUntil(".k-treeview", ".k-item").map(function () { return $(this).index(); }).toArray().reverse().join(":"); } $(document).ready(function () { var itemInfoTemplate = kendo.template($("#itemInfoTemplate").html()); var treeview = $("#CategoryTreeView"); treeview.on("change", ":checkbox", function (e) { var checkbox = $(this), dataItem = treeview.data("kendoTreeView").dataItem(checkbox.closest(".k-item")), index = getNodeIndex(checkbox); checkbox.nextAll().remove(); if (checkbox.is(":checked")) { checkbox.after(itemInfoTemplate({ item: dataItem, index: index })); } }); }); </script> <h2>Load Summary</h2>
@(Html.Kendo().Grid<MyProject.Models.Invoice>()
.Name("grid")
.HtmlAttributes(new { style = "width: 100%" } )
.Columns(columns =>
{
columns.Template(@<text>@Html.ActionLink("Details", "Invoice", "Details", new { id = @item.InvoiceID })</text>)
.ClientTemplate("<a href='/Invoice/Details/#= InvoiceID#'>Details</a>").Width("5%");
columns.Bound(p => p.InvoiceNumber).Width("5%").Title("Load No.");
columns.Bound(p => p.BookDate).Format("{0:d}").Width("5%");
})
.DataSource(datasource => datasource
.Ajax()
.Read(read => read.Action("GetLoads", "Invoice"))
.Model(m => m.Id(model => model.InvoiceID))
)
.Pageable()
.Sortable()
.Filterable()
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Single))
)
Here are my controller actions:
public ActionResult Index()
{
IEnumerable<Invoice> invoices = _db.Invoices.Where(p => p.SalesmanID == _salesmanId);
return View(invoices.ToList());
}
//
// GET: /Invoice/Details/5
public ActionResult Details(int id = 0)
{
Invoice invoice = _db.Invoices.Find(id);
if (invoice == null)
{
return HttpNotFound();
}
_routeValues = this.GridRouteValues();
InvoiceViewModel invoiceViewModel = Mapper.Map<Invoice, InvoiceViewModel>(invoice);
return View(invoiceViewModel);
}
[HttpPost]
public ActionResult Details(string btnSubmit)
{
return RedirectToAction("Index", _routeValues);
}
@(Html.Kendo().DropDownListFor(x => x.Event.DisconnectionId) .DataValueField("Id") .DataTextField("Name") .DataSource(source => { source.Read(read => { read.Action("_Disconnections", "Event"); }) .ServerFiltering(true); }) )<input id="Event_DisconnectionId" name="Event.DisconnectionId" type="text" value="0" /><script> jQuery(function(){jQuery("#Event_DisconnectionId").kendoDropDownList({dataTextField:"Name",dataValueField:"Id"});});