I am trying to add Custom Button to each row of Kendo Grid, but I am not getting the desired output.So my requirement is to add dynamic buttons to each row and on clicking on these button I need to process few thing for which I need few column values to be passed to that button click.
I have tried something like
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.Id);
columns.Bound(o => o.TBRId).Width(100).Title(UI_Resources.ListLabel_TBRId);
columns.Bound(o => o.THUQuantity).Width(50).Title(UI_Resources.ListLabel_THUQuantity).HtmlAttributes(new { style = "text-align:right" });
columns.Bound(o => o.Id).ClientTemplate("<input width='50px' type='button' value= " + UI_Resources.Button_Details + " onclick='onDetailUnitClick(#= Id #);' class='btn btnTable' />").Width(50).Title("");
columns.Bound(o => o.IsPOD).ClientTemplate("#= AppendZeroPODButton(Id,IsPOD) #").Width(60).Title("");
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetUnitsForShipment", "POD",new { shipmentId = @Model, Mode = "POD" }))
)
)
/*JavaScript */
function onDetailUnitClick(Id) {
var podDateTime = $("#enteredPODDateTime").val();
var stopId = $("#hiddenStopId").val();
var mode = '';
if (typeof $("#hiddenMode").val() != 'undefined')
mode = $("#hiddenMode").val();
window.location.href = "/POD/Details/" + Id + "?stopId=" + stopId + "&date=" + podDateTime + "&mode=" + mode;
};
function AppendZeroPODButton(Id, isPOD) {
if (isPOD == true) {
return "<input width='100px' type='button' value= 'Zero POD' onclick='onPODUnitClick(" + Id + ",1);' class='btn btnTable btn-success' disabled />";
}
else {
return "<input width='100px' type='button' value= 'Zero POD' onclick='onPODUnitClick(" + Id + ",1);' class='btn btnTable btn-danger' />";
}}
Can you please suggest me what I am doing wrong!! It was working for Telerek MVC grids.
Thanks Yogendra Singh
One way you can add a custom button is to include a custom command button in the toolbar. Next, on the click event of the button, add the logic to open the Kendo UI Window: $("#grid"). on("click", "#customButton", function (e) { e.
It worked if I change the ClientTemplate to
columns.Template(t => t.IsPOD).HeaderTemplate("").ClientTemplate(@"<a href='javascript: void(0)' class='btn btnTable' onclick='onDetailUnitClick(#= Id #)' title='button delete'>" + UI_Resources.Button_Details + " </a>").Title("").Width(50);
AND
columns.Bound(p => p.IsPOD).ClientTemplate("# if( IsPOD == true) { # <a href='javascript: void(0)' class='btn btnTable btn-success' onclick='onPODUnitClick(#= Id #, 1)' title='Zero POD'>" + UI_Resources.Button_ZeroPOD + "</a> # } else {# <a href='javascript: void(0)' class='btn btnTable btn-danger' onclick='onPODUnitClick(#= Id #, 1)' title='Zero POD'>" + UI_Resources.Button_ZeroPOD + "</a> # } #").Title("").Width(100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With