or
@(Html.Kendo().Grid<StatusPage.Models.Appliance>() .Name("grid") .Columns(columns => { columns.Bound(p => p.Title); columns.Bound(p => p.CurrentStatus).Width(100); columns.Command(command => { command.Edit(); command.Destroy(); }).Width(172); }) .ToolBar(tools => { tools.Create(); }) .Sortable() .Pageable() .Filterable() .DataSource(dataSource => dataSource .WebApi() .Model(model => { model.Id(p => p.Id); }) .Events(events => events.Error("error_handler")) .Read(read => read.Url(Url.HttpRouteUrl("Appliance", new { controller = "Appliances" }))) .Create(create => create.Url(Url.HttpRouteUrl("Appliance", new { controller = "Appliances" }))) .Update(update => update.Url(Url.HttpRouteUrl("Appliance", new { controller = "Appliances", id = "{0}" }))) .Destroy(destroy => destroy.Url(Url.HttpRouteUrl("Appliance", new { controller = "Appliances", id = "{0}" }))) ))<script>function error_handler(e) { var errors = $.parseJSON(e.xhr.responseText); if (errors) { alert("Errors:\n" + errors.join("\n")); }}</script>public class AppliancesController : BaseApiController { public AppliancesController(IRepository repo) : base(repo) { } public DataSourceResult Get([System.Web.Http.ModelBinding.ModelBinder(typeof(WebApiDataSourceRequestModelBinder))]DataSourceRequest request) { //var appliances = TheRepository.GetAppliances().ToList() // .Select(m => TheModelFactory.Create(m)); var appliances = new List<Appliance>() { new Appliance() { Title = "Appliance 1", CurrentStatus = 2 } }; return appliances.ToDataSourceResult(request); } public HttpResponseMessage Get(int appId) { try { var entity = TheRepository.GetAppliance(appId); if (entity == null) return Not_Found(); return Request.CreateResponse(HttpStatusCode.OK, TheModelFactory.Create(entity)); } catch { // TODO logging } return Bad_Request(); } public HttpResponseMessage Post([FromBody] Appliance model) { try { if (!ModelState.IsValid) return Bad_Request(); model.CurrentStatus = (int)StatusType.Operational; model.LastUpdated = DateTime.Now; if (TheRepository.Insert(model) && TheRepository.SaveAll()) { return Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(model)); } } catch { // TODO logging } return Bad_Request(); } [HttpDelete] public HttpResponseMessage Delete(int appId) { try { var entity = TheRepository.GetAppliance(appId); if (entity == null) return Not_Found(); if (TheRepository.DeleteAppliance(entity) && TheRepository.SaveAll()) { return Request.CreateResponse(HttpStatusCode.OK); } } catch { // TODO logging } return Bad_Request(); } [HttpPut] [HttpPatch] public HttpResponseMessage Patch(int appId, [FromBody] Appliance model) { try { if (!ModelState.IsValid || appId != model.Id) return Bad_Request(); if (TheRepository.UpdateAppliance(model) && TheRepository.SaveAll()) { return Request.CreateResponse(HttpStatusCode.OK); } } catch (Exception ex) { return Bad_Request(ex); } return Bad_Request(); } }<h2>Delete Selected Transaction</h2><br />@* The DIV where the Kendo grid will be initialized *@<div id="grid"></div><script id="popup_editor" type="text/x-kendo-template"><p> <h4> Enter Reason to Delete this Transaction</h4></p><div class="k-edit-label"><label for="Notes">Notes</label></div> <textarea name="Notes" data-bind="value: Notes" class="k-textbox" required validationMessage="Notes is required." style="height: 100px;"></textarea></script><script> $(function () { $("#grid").kendoGrid({ dataSource: { transport: { read: { url: "GetJournalsFromLoadByID", contentType: "application/json; charset=utf-8", type: "POST", cache: true, data: { tkey: @Request["tkey"] } }, update: { url: "@Url.Action("EditingPopup_Delete","Journals")", type: "POST", complete: function(e) { alert("Successfully Deleted - Transactionn"); $("#grid").data("kendoGrid").dataSource.read(); }, error: function (e) { alert("Manage: DeleteTransaction -> Ajax Error!"); } }, parameterMap: function (data, operation) { if (operation != "read") { var result = {}; for (var i = 0; i < data.models.length; i++) { var tk = data.models[i]; var c = new Date(tk.CreatedDate); tk.CreatedDate = kendo.toString(new Date(c), "F"); for (var member in tk) { result["newTkey[" + i + "]." + member] = tk[member]; } } return result; } else { return JSON.stringify(data) } } }, schema: { data: "Data", total: "Total", model: { id: "TRANSACTION_KEY", fields: { TRANSACTION_KEY: { editable: false, nullable: true }, Notes: { editable: true, validation: { required: true } } } } }, pageSize: 1000, serverPaging: true, serverFiltering: true, serverSorting: true }, groupable: true, columnMenu: true, filterable: true, sortable: true, pageable: true, columns: [ { field: "TRANSACTION_KEY", title: "TRANSACTION_KEY", width: "100px" }, { field: "FISCAL_YEAR ", title: "FISCAL_YEAR", width: "150px" }, { field: "ACCOUNTING_PERIOD", title: "ACCOUNTING_PERIOD", width: "150px" }, { field: "Notes", width:"250px" }, { command: ["edit"], title:"Update Delete Reason", width:"200px"}], //["edit","destroy"] editable: { mode: "popup", template: kendo.template($("#popup_editor").html()) } }); });</script><script type="text/kendo-template" id="message"><div class="k-widget k-tooltip k-tooltip-validation k-invalid-msg field-validation-error" style="margin: 0.5em; display: block; " data-for="#=field#" data-valmsg-for="#=field#" id="#=field#_validationMessage"> <span class="k-icon k-warning"> </span>#=message#<div class="k-callout k-callout-n"></div></div></script><script type="text/javascript"> var validationMessageTmpl = kendo.template($("#message").html()); function error(args) { if (args.errors) { var grid = $("#grid").data("kendoGrid"); grid.one("dataBinding", function (e) { e.preventDefault(); // cancel grid rebind if error occurs for (var error in args.errors) { showMessage(grid.editable.element, error, args.errors[error].errors); } }); } } function showMessage(container, name, errors) { //add the validation message to the form container.find("[data-valmsg-for=" + name + "],[data-val-msg-for=" + name + "]") .replaceWith(validationMessageTmpl({ field: name, message: errors[0] })) }</script>
@(Html.Kendo().Grid(Model) .Name("BatchGrid") .Pageable() .Sortable() .Scrollable() .HtmlAttributes(new { style = "height:525px; width:1200px" }) .Columns(columns => { columns.Bound(b => b.BatchID) .Width("300px") .Title("Batch ID") .Visible(false); columns.Bound(b => b.ShortBatchID) .Width("100px") .Title("Batch ID"); columns.Bound(b => b.HasErrorTransaction) .Width("50px") .Title("Err").Visible(false); columns.Command(c => c.Custom("Post Batch") .Click("onClickPostBatch") .HtmlAttributes(new { style = "width:100px;" })); columns.Bound(b => b.Created_Emp_Name) .Width("200px") .Title("Created Employee"); columns.Bound(b => b.Transmitted_DateTime) .Width("175px") .Format("{0:MM/dd/yyyy hh:mm tt}") .Title("Transmitted"); columns.Bound(b => b.Completed_DateTime) .Width("175px") .Format("{0:MM/dd/yyyy hh:mm tt}") .Title("Completed"); columns.Command(c => c.Custom("Delete Batch") .Click("onClickDeleteBatch") .HtmlAttributes(new { style = "width:100px;" })); } ) .DataSource(dataSource => dataSource .Ajax() .Sort(sort => sort.Add("HasErrorTransaction").Ascending()) // <-- initial sort .PageSize(12) .Read(read => read.Action("FetchBatchCollection", "Home").Data("addlData")) .ServerOperation(false) ) .Events(events => events.DataBound("onBatchGridDataBound") .DetailExpand("onBatchGridExpand")) .ClientDetailTemplateId("transactions") )<!-- Nested grid for transaction object, member of BatchHeader.TranCollection There can be many ITransaction objects per BatchHeader --><script id="transactions" type="text/kendo-tmpl"> @(Html.Kendo().Grid<ROAMTranReview.ROAMHostSvc.TransactionBase>() .Name("TranGrid_#=BatchID#") // makes the sub-grid name unique so that it will be displayed on each child row. .HtmlAttributes(new { style = "height:535px; width:1400px" }) .Columns(columns => { columns.Bound(b => b.BatchID) .Visible(false); columns.Bound(b => b.TransactionType) .Visible(false); columns.Bound(b => b.ID) .Width("300px") .Title("Transaction ID") .Visible(false); columns.Bound(b => b.ShortTranID) .Width("100px") .Title("Tran ID"); columns.Command(c => c.Custom("View Transaction") .Click("onClickViewTransaction") .HtmlAttributes(new { style = "width:100px;" })); columns.Bound(b => b.TranTypeDisplayText) .Width("100px") .Title("Type"); columns.Bound(b => b.ItemID) .Width("100px") .Title("Item ID"); columns.Bound(b => b.ItemDescription) .Width("300px") .Title("Item Description"); columns.Bound(b => b.Quantity) .Width("50px") .Title("Qty"); columns.Bound(b => b.WorkOrderTask) .Width("100px") .Title("Workorder"); columns.Bound(b => b.EmployeeName) .Width("200px") .Title("Employee"); columns.Command(c => c.Custom("Delete Transaction") .Click("onClickDeleteTransaction") .HtmlAttributes(new { style = "width:155px;" })); columns.Bound(b => b.PostingFlagDisplayText) .Width("150px") .Title("Posting Flag"); }) .Scrollable() .Pageable() .DataSource(dataSource => dataSource .Ajax() .PageSize(6) .Read(read => read.Action("FetchTransactionCollection", "Home", new { batchID = "#=BatchID#" })) ) .Events(events => events.DataBound("onTranGridDataBound") .DetailExpand("onTranGridExpand")) .ToClientTemplate() )</script>