How to add Custom Button in each row in Kendo Grid

20,405

Solution 1

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);

Solution 2

You can add Custom button as well.Refer this http://demos.kendoui.com/web/grid/custom-command.html

Share:
20,405
Yogendra Singh
Author by

Yogendra Singh

Updated on December 13, 2020

Comments

  • Yogendra Singh
    Yogendra Singh over 3 years

    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