Auto calculate Kendo Grid Column - model-view-controller

I want to Auto calculate Kendo Grid Column on client side. My code is
#(Html.Kendo().Grid(Model)
.Name("VATGrid")
.Columns(columns =>
{
columns.Bound(p => p.BaseAmount);
columns.Bound(x => x.Unit);
columns.Bound(p => p.VATPercentage);
columns.Bound(p => p.VATAmount)
.HeaderHtmlAttributes(new { title = "VAT Amount" })
.HtmlAttributes(new { style = "text-align:right" })
.Title("VAT Amount")
.ClientTemplate(
"#= VATAmount=kendo.toString(BaseAmount*Unit*VATPercentage, 'n2')#" +
"<input type='hidden' class='VATAmount' value='#=kendo.toString(BaseAmount*Unit*VATPercentage, 'n4')#' />");
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Model(model =>
{
model.Id(p => p.DocumentVATID);
model.Field(x => x.CompanyVATType).Editable(false);
model.Field(x => x.VATPercentage).Editable(false);
model.Field(x => x.VATType).Editable(false);
model.Field(x => x.BaseAmount).DefaultValue(0);
model.Field(x => x.Unit).DefaultValue(0);
})
)
Where I am able to get Auto calculated value but after clicking on the Grid Cell.
I want to show calculated value on change itself

Something like this?
#(Html.Kendo().Grid(Model)
.Name("VATGrid")
.Columns(columns =>
{
columns.Bound(p => p.BaseAmount);
columns.Bound(x => x.Unit);
columns.Bound(p => p.VATPercentage);
columns.Bound(p => p.VATAmount)
.HeaderHtmlAttributes(new { title = "VAT Amount" })
.HtmlAttributes(new { style = "text-align:right" })
.Title("VAT Amount")
//.ClientTemplate(
//"#= VATAmount=kendo.toString(BaseAmount*Unit*VATPercentage, 'n2')#" +
//"<input type='hidden' class='VATAmount' value='#=kendo.toString(BaseAmount*Unit*VATPercentage, 'n4')#' />");
//})
.ClientTemplate(
"<span id="vatId">#= VATAmount=kendo.toString(BaseAmount*Unit*VATPercentage, 'n2')#</span>" +
"<input type='hidden' class='VATAmount' value='#=kendo.toString(BaseAmount*Unit*VATPercentage, 'n4')#' />");
})
//put span tag around the clienttemplate above
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Events(e => e.Change("onProductChange")) //add this event listener
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Model(model =>
{
model.Id(p => p.DocumentVATID);
model.Field(x => x.CompanyVATType).Editable(false);
model.Field(x => x.VATPercentage).Editable(false);
model.Field(x => x.VATType).Editable(false);
model.Field(x => x.BaseAmount).DefaultValue(0);
model.Field(x => x.Unit).DefaultValue(0);
})
)
<script type="text/javascript">
function onChange(e) {
var selected = $.map(this.select(), function (item) {
return $(item).text();
});
console.log("Selected: " + selected.length + " item(s), [" + selected.join(", ") + "]");
//TODO: calculate your data and use calc variables below
var calc1 = 0;
var calc2 = 0;
$("#vatId").text(calc);
$(".VATAmount").val(calc2); //or something like that, but you get the grip
}
</script>
Perhaps I´m misunderstanding your problem but it sounds to me as if you want to calculate the data in your footertemplate each time a cell is selected.

Related

Invalid Tempate error on nested grids inside editorTemplate popup of ASP.NET Core Kendo Grid

I have a ASP.NET Core Kendo grid which display's list of Users. The grid has pouup mode editor template. The Kendo Grid code looks like this.
#(Html.Kendo().Grid<Anju.PubSTRAT.Web.Areas.Admin.Models.UserViewModel>()
.Name("UserGrid")
.Columns(columns =>
{
columns.Command(command =>
{
if (UserAccessService.CanEdit("User"))
{
command.Edit().UpdateText("Submit").Text(" ");
command.Custom("Clear").Text(" ").IconClass("k-icon k-i-clear-css k-grid-features").HtmlAttributes(new { title = "Clear User", #class = "k-grid-custom" }).Click("User_clearUser");
command.Custom("Email").Text(" ").IconClass("k-icon k-i-envelop").HtmlAttributes(new { title = "Send Welcome Email", #class = "k-grid-custom" }).Click("User_sendWelcomeEmail");
command.Custom("Unlock").Text(" ").IconClass("k-icon k-i-unlock").Visible("function (e) { return (!e.IsLockedOut); }").HtmlAttributes(new { title = "Disable User", #class = "k-grid-custom" }).Click("User_disableUser");
command.Custom("Lock").Text(" ").IconClass("k-icon k-i-lock").Visible("function (e) { return (e.IsLockedOut); }").HtmlAttributes(new { title = "Enable User", #class = "k-grid-custom" }).Click("User_enableUser");
command.Custom("UserFile").Text(" ").IconClass("k-icon k-i-file").HtmlAttributes(new { title = "User Profile File", #class = "k-grid-custom" }).Click("User_openFilePopup");
}
}).Width(75);
columns.Bound(p => p.UserId).Hidden(true);
columns.Bound(p => p.UserName).MinResizableWidth(100);
columns.Bound(p => p.Prefix).MinResizableWidth(50);
columns.Bound(p => p.FirstName).MinResizableWidth(50);
columns.Bound(p => p.LastName).MinResizableWidth(50);
columns.Bound(p => p.Suffix).MinResizableWidth(50);
columns.Bound(p => p.Email).MinResizableWidth(100);
columns.Bound(p => p.PhoneNumber).MinResizableWidth(60);
})
.ToolBar(toolbar =>
{
toolbar.Custom().Text("Reset Filters").HtmlAttributes(new { id = "resetAllGridFilters", #class = "btn-grid-toolbar", onclick = "ResetGridFilter(\"UserGrid\")" });
if (UserAccessService.CanAdd("User"))
{
toolbar.Create().Text("Add New User").HtmlAttributes(new { #class = "btn-grid-toolbar" });
}
if (UserAccessService.IsAnjuAdmin)
{
toolbar.Custom().Text("Flag Reset Security").HtmlAttributes(new { id = "flagResetSecurity",#class = "btn-grid-toolbar", onclick = "User_flagResetSecurity()" });
toolbar.Custom().Text("Unflag Reset Security").HtmlAttributes(new { id = "unFlagResetSecurity",#class = "btn-grid-toolbar", onclick = "User_unFlagResetSecurity()" });
}
toolbar.Custom().Text("Show Disabled Users").HtmlAttributes(new { id = "showHideDisabledUsers", #class = "btn-grid-toolbar", onclick = "showHideDisabledUsers()" });
})
.Pageable(pageable => pageable
.Refresh(true)
.Responsive(false)
.PageSizes(Constants.PageSizes)
.ButtonCount(5))
.Sortable()
.Scrollable()
.Resizable(resize => resize.Columns(true))
.Filterable()
.Events(e => e.DataBound("gridDataBoundAutoFit"))
.Events(e => e.Edit("User_AddEditUser"))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(UserAccessService.PageSize)
.ServerOperation(true)
.Events(e => e.RequestEnd("User_AddProductDetails"))
.Events(events => events.Error("onGridError"))
.Model(model => model.Id(p => p.UserId))
.Read(read => read.Action("GetUserList", "User").Data("getUserDetailsOptions"))
.Create(create => create.Action("AddUser", "User"))
.Update(update => update.Action("UpdateUser", "User")))
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("User").Window(w => w.Height(670).Width(600)))
)
The Editor template is having tab strips and one of tab is having nested Kendo grid.
The Code for the ASP.NET Core Kendo Grid is as follows :
<script id="UserProductSegmentTemplate" type="text/kendo">
#(Html.Kendo().Grid<Anju.PubSTRAT.Web.Areas.Admin.Models.SegmentViewModel>()
.Name("UserProductSegmentGrid#=ProductId#")
.Columns(columns =>
{
columns.Select().Width(50);
columns.Bound(c => c.SegmentId).Width(0).Hidden();
columns.Bound(c => c.Name).Title("Segment Name").Width(100);
})
.Sortable()
.Scrollable()
.PersistSelection()
.NoRecords(records => records.Template("No Records."))
.DataSource(dc => dc.Ajax()
.ServerOperation(true)
.Model(model => model.Id(p => p.SegmentId))
.Read(read => read.Action("GetSegmentList", "Segment", new { productId = 1 }))
)
.ToClientTemplate()
)
</script>
<div class="row">
#(Html.Kendo().Grid<Anju.PubSTRAT.Web.Areas.Admin.Models.ProductViewModel>()
.Name("ProductGrid")
.Columns(columns =>
{
columns.Select().Width(50);
columns.Bound(p => p.ProductId).Hidden(true);
columns.Bound(p => p.Name).MinResizableWidth(200);
columns.Bound(p => p.Identifier).MinResizableWidth(150);
columns.Bound(p => p.GenericName).MinResizableWidth(150);
})
.Pageable(pageable => pageable
.Refresh(true)
.Responsive(true)
.PageSizes(Constants.PageSizes)
.ButtonCount(5))
.Sortable()
.Scrollable()
.Resizable(resize => resize.Columns(true))
.Filterable()
.PersistSelection()
.Events(e => e.Change("onUserProductGridChange"))
.Events(e => e.DataBound("onUserProductDataBound"))
.ClientDetailTemplateId("UserProductSegmentTemplate")
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(UserAccessService.PageSize)
.ServerOperation(true)
.Model(model => model.Id(p => p.ProductId))
.Read(read => read.Action("GetProductList", "Product")))
.ToClientTemplate()
)
</div>
When I click on "Add New User" toolbar button the editor popup opens but grid is not getting rendered and getting "Invalid template" in browser console.

Kendo MVC grid with ClientGroupHeaderTemplate with ClientTemplate checkboxes validation

I am using Kendo MVC grid with ClientGroupHeaderTemplate with ClientTemplate checkboxes as one of the column. Under each group there are check boxes, At least one check box should be selected under each group. How do I loop through each groups and validate if check box is checked or not. Please help.
#(Html.Kendo().Grid<Arthama.Web.GlobalvaluesModels.Model.Model>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.Type).Title("Type").ClientGroupHeaderTemplate("#= items[0].Type#").Hidden(true);
columns.Bound(p => p.Text).Visible(true).Width(50).Title("SubType").Filterable(x => x.Cell(y => y.Template("template").ShowOperators(false).Operator("contains")));
columns.Bound(p => p.Value).Visible(false).Width(50).Title("Value");
columns.Bound(c => c.Check).Width(40).Title("Check").ClientTemplate("<input name='Check' type='checkbox' #= Check? checked='checked': '' # class='chk_row' />").HtmlAttributes(new { style = "text-align: center" }).Filterable(false).HeaderHtmlAttributes(new { style = "text-align:center" }).Filterable(false).Sortable(false);
})
.HtmlAttributes(new { #style = "height:390px;" })
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.AutoBind(false)
.DataSource(dataSource => dataSource
.Ajax()
.Sort(x => x.Add("Check").Descending())
.Group(group => group.Add(p => p.Type))
.Batch(true)
.ServerOperation(false)
.PageSize(1000)
.Read(read => read.Action("Action", "Controller").Data("param"))
)
.Pageable()
.Sortable()
.Events(e => e.DataBound("DBound"))
.Scrollable()
.Resizable(resize => resize.Columns(true))
)
This is what I am trying, but this won't loop through groups
var len = $("#grid").data("kendoGrid").dataSource.data().length;
var data = $("#grid").data("kendoGrid").dataSource.data();
for (i = 0; i < len; i++) {
if (data[i].Check=== true) {
}
}

Kendo Grid pagination is not working with responsive plugin footable

Hi I have a kendo grid which is responsive using footable plugin. It is working fine. But when i click the pagination it is breaking the ui. Attached the image of the page. Can you pls help to fix this?
#(Html.Kendo().Grid<UCM.UCW.PresentationService.Entity.Dto.Task>()
.Name("ValidationTaskListGrid")
.HtmlAttributes(new { #class = "table-bordered" })
.TableHtmlAttributes(new { #class = "footable" })
.Columns(columns =>
{
columns.Bound(p => p.TaskDueDate)
.Sortable(true)
.Title("Due Date")
.HeaderHtmlAttributes(new { data_class = "expand" });
columns.Bound(p => p.StateCode)
.Sortable(true)
.Title("State")
.HeaderHtmlAttributes(new { data_hide = "phone_s" });
columns.Bound(p => p.DocumentType)
.Sortable(true)
.Title("Document Type")
.HeaderHtmlAttributes(new { data_hide = "phone,phone_s" });
columns.Bound(p => p.Form)
.Sortable(true)
.Title("Form")
.HeaderHtmlAttributes(new { data_hide = "phone,tablet,phone_s" });
columns.Bound(p => p.UnemploymentDocumentId)
.Sortable(true)
.Title("Document ID")
.HeaderHtmlAttributes(new { data_hide = "phone,tablet,phone_s" });
columns.Bound(p => p.TaskSubject)
.Sortable(true)
.Title("Task Name ")
.HeaderHtmlAttributes(new { data_hide = "phone,tablet,phone_s" });
columns.Bound(p => p.TaskAssignedTo)
.Sortable(true)
.Title("Assigned To ")
.HeaderHtmlAttributes(new { data_hide = "phone,tablet,phone_s" });
columns.Bound(p => p.InstanceName)
.Sortable(false)
.Title("Actions")
// .HeaderHtmlAttributes(new { data_hide = "phone,phone_s" })
.HtmlAttributes(new { style = "text-align: center" })
.ClientTemplate("<a href = '" + Url.Action("GetUnemploymentDocument", "UnemploymentDocument",
new { UnemploymentDocumentId = "#=UnemploymentDocumentId#", taskId = "#=TaskId#", taskAssignedToType = "#=TaskAssignedToType#" }) + "' class='btn btn-function'>Start Task</a>");
})
.Pageable(pageable => pageable.ButtonCount(6)
.Messages(m => m.Display("Showing {0}-{1} of {2}")))
.Sortable(sortable => sortable.SortMode(GridSortMode.SingleColumn).AllowUnsort(false))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetValsync", "WorkList"))
//.ServerOperation(WebConstants.EnableServerOperation)
.ServerOperation(true)
.PageSize(AppContextHelper.Instance.ApplicationConfiguration.DefaultViewItem)
.Sort(sort =>
{
sort.Add("TaskDueDate").Descending();
}))
.Events(x => x.DataBound("GridDataBound")
))

Telerik grid column command , add to url # on click

I have this telerik grid in a asp.net mvc project
<div class="actualGrid" id="actualGrid">
#(Html.Kendo().Grid<AVNO_KPMG.Models.Bench>() //Bench Grid
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.name).Title("Bench").Filterable(ftb => ftb.Cell(cell => cell.Operator("startswith"))).Width(100);
columns.Bound(p => p.freeSeats).Title("Free Seats").Width(200).Filterable(ftb => ftb.Cell(cell => cell.Operator("gte"))).HtmlAttributes(new { #class = "FreeSeats" })
.ClientTemplate("<div class='barthingy'><div class='bars_text'><div class='seatsText'><span class=\"bookNotfull\"></span> <b>#=bookedSeats#</b> USED SEATS</div><div class='seatsText'><span class=\"bookfull\"></span> <b>#=freeSeats#</b> TOTAL OFSEATS</div></div><div id='bigbar'><div class='bigbar' style='width:100%; float:left; background-color:rgb(142, 188, 0);'><div ' style='float:right; width:#=bookedSeats *100 / seatsCount#%; background-color:rgb(255, 99, 71); height:16px ' class='b_#=name#' id='temp-log'></div></div></div></div>");
//buttons
columns.Command(command => { command.Custom("checkBench1 ").Text(" AM ").Click("doCheckIn"); command.Custom("checkBench 2").Text(" PM ").Click("doCheckIn"); command.Custom("checkBench3").Text("All Day").Click("doCheckIn"); }).HtmlAttributes(new { #class = "comms#=freeSeats# freeAM#=seatsCount - (bookings_am + bookings_allday)# freePM#=seatsCount - (bookings_pm + bookings_allday)# freeALLDAY#=freeSeats#" }).Title("Check in").Width(200);
})
.Pageable()
.Sortable()
.Scrollable(scrolling => scrolling.Enabled(false))
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
//.HtmlAttributes(new { style = "height:530px;" })
.Events(events => events.DataBound("onDataBound"))
.DataSource(dataSource => dataSource
.Ajax()
//.Sort(sort => sort.Add("freeSeats").Ascending())
.PageSize(10)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.id))
.Read(read => read.Action("GetBenches", "Deskcheckin"))
)
)
</div>
Everytime i press on of the buttons in the command column, the url gets a # in front of it, even if i set the buttons to do nothing.
my url is something like
http://www.aaaaaa.com/stuff
When i press one of the buttons i get
http://www.aaaaaa.com/stuff#
How can i disable this?
Please try with the below code snippet. For custom command button grid generate anchor control for same. By default it set href='#' and I have replaced it with href='javascript:void(0)'.
<div>
#(Html.Kendo().Grid<MvcApplication1.Models.Student>()
.Name("grid")
.Columns(columns =>
{
..........
..........
columns.Command(command => { command.Custom("checkBench1").Text("AM").Click("doCheckIn"); }).Title("Check in").Width(200);
})
.Events(events => events.DataBound("onDataBound"))
..........
..........
)
</div>
<script>
function doCheckIn() {
alert('a');
}
function onDataBound(arg) {
$("#.k-grid-checkBench1").attr('href', 'javascript:void(0)');
}
</script>
Let me know if any concern.

Getting the value of a column in a child grid in a kendo grid hierarchy

I have a Kendo grid hierarchy and was wondering how to go about getting the value of a column in the child grid so I can pass that value to a function in the controller. The data in the parent grid is being pulled from one db table which is a quote entry and the child grid is pulling from another table which contains line item versions of the quote. In the child grid, I click the edit button to pass a value to a controller. I get an error saying that VersionID is undefined. How do I go about getting the value from the VersionID column in the child grid?
Here is code for the parent grid:
#(Html.Kendo().Grid<myWilmer.Models.QuotesSearchViewModel>()
.Name("quotesSearchGrid")
.Columns(columns =>
{
columns.Bound(c => c.AccountNumber);
columns.Bound(c => c.QuoteNumber);
columns.Bound(c => c.CustomerName);
columns.Template(c => { }).ClientTemplate(
Html.ActionLink("Create Version", "CreateQuoteVersion", new { id = "#= QuoteNumber #" }, new { #class = "k-button" }).ToHtmlString());
})
.ToolBar(toolbar => toolbar.Custom().Text("Create New Quote").Action("Index", "Quotes"))
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Single))
.Sortable()
.ClientDetailTemplateId("template")
.Events(events => events.DataBound("onDataBound"))
.Pageable(pageable => pageable
.ButtonCount(5)
.PageSizes(new int[] { 10, 20, 30 }))
.Navigatable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Model(model =>
{
model.Id(m => m.QuoteNumber);
model.Field(m => m.AccountNumber).Editable(false);
model.Field(m => m.QuoteNumber).Editable(false);
model.Field(m => m.CustomerName).Editable(false);
})
.Read(read => read.Action("Quotes_Read", "Quotes").Data("filters"))
.Events(e => e.Error("ShowAjaxError"))
.Create(update => update.Action("EditingInline_Create", "Quotes"))
)
)
And here is code for the child grid:
<script id="template" type="text/kendo-templ">
#(Html.Kendo().Grid<myWilmer.Models.QuoteVersionViewModel>()
.Name("quoteDetailsGrid_#=QuoteNumber#")
.Columns(columns =>
{
columns.Bound(c => c.VersionID);
columns.Bound(c => c.JobType);
columns.Bound(c => c.ProductType);
columns.Bound(c => c.RepName);
columns.Bound(c => c.TimeIn).Format("{0:hh:mm:ss tt}");
columns.Bound(c => c.DateIn).Format("{0:MM/dd/yyyy}");
columns.Template(c => { }).ClientTemplate(
Html.ActionLink("Edit", "Edit", new { id = "#= QuoteNumber #", itemID = "#= VersionID #" }, new { #class = "k-button" }).ToHtmlString());
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Read(read => read.Action("Versions_Read", "Quotes", new { quoteNumber = "#=QuoteNumber#" }))
.Model(model => {
model.Id(m => m.VersionID);
model.Field(m => m.VersionID).Editable(false);
model.Field(m => m.JobType).Editable(false);
model.Field(m => m.ProductType).Editable(false);
model.Field(m => m.RepName).Editable(false);
model.Field(m => m.TimeIn).Editable(false);
model.Field(m => m.DateIn).Editable(false);
})
)
.Pageable(pageable => pageable
.ButtonCount(5)
.PageSizes(new int[] { 10, 20, 30 }))
.Sortable()
.ToClientTemplate()
)
Here is the controller method
public ActionResult Edit(string id, int itemID)
{
//Functionality
}
Thanks in advance - Shaun
You should use:
\\#= VersionID\\#
in the child grid.
Here is the solution we came up with. In the view model, we created a property called "EditButton" and set it to a string with HTML markup:
QuoteVersionViewModel qvvm = new QuoteVersionViewModel()
{
QuoteNumber = deet.QuoteNum,
VersionID = deet.VersionID,
ProductType = deet.ProductType,
JobType = deet.JobType,
RepName = deet.RepName,
TimeIn = deet.TimeIn,
DateIn = deet.DateIn,
EditButton = "<a href='" +u.Action("Edit", "Quotes", new { id = deet.QuoteNum, versionID = deet.VersionID }) + "' class='k-button'>Edit</a>"
};
And our Kendo grid columns looks like this:
.Columns(columns =>
{
columns.Bound(c => c.QuoteNumber);
columns.Bound(c => c.VersionID);
columns.Bound(c => c.JobType);
columns.Bound(c => c.ProductType);
columns.Bound(c => c.RepName);
columns.Bound(c => c.TimeIn).Format("{0:hh:mm:ss tt}");
columns.Bound(c => c.DateIn).Format("{0:MM/dd/yyyy}");
columns.Bound(c => c.EditButton).Encoded(false);
})

Resources