Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Custom Button in each row in Kendo Grid

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

like image 814
Yogendra Singh Avatar asked Mar 19 '13 12:03

Yogendra Singh


People also ask

How do I add a custom button to Kendo grid toolbar?

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.


1 Answers

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);
like image 99
Yogendra Singh Avatar answered Oct 02 '22 11:10

Yogendra Singh