This is a migrated thread and some comments may be shown as answers.

KendoUI Grid Column Command : Button Name

2 Answers 714 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Arvind
Top achievements
Rank 1
Arvind asked on 11 Sep 2013, 04:21 PM
I have a KendoUI Grid with columns as below.

 columns: [
                           { field: "username", title: "Email Id",  width: 120 },
                           { field: "firstName", title: "First Name", width: 110 },
                           { field: "lastName", title: "Last Name", width: 110 },
                           { field: "phone", title: "Phone Number", width: 90 },
                           { command: "edit",  title: " ", width: 90 },
                           { command: {text: getButtonText(), click: deleteUser }, title: " ", width: 90 }
]

function getButtonText(e){
            alert(e);
            var data = this.dataItem($(e.currentTarget).closest("tr"));
return "test";
 
}

function deleteUser(e){
}

The last command , the label/text of the button depends on the data. It could be different for every row. e.g. Delete , Lock, Unlock etc...

For that I have written a function getButtonText(e) above to decide the button text. 

When I run this, the variable e in the function is undefined.

Please help me if you know the solution.

Thanks,


                                     

2 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 12 Sep 2013, 09:32 AM
Hello Arvind,

columns.command.text property accepts a string, not function. If you want to execute a function every time the button is rendered you should use a template. For your convenience I prepared a small sample that demonstrates the implementation:

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Misahael
Top achievements
Rank 1
answered on 14 Oct 2013, 02:57 PM
Hello,

I have the same problem,. I need a custom text for each command button.

The label/text of the button depends on the data (E.g personal, name or DNI). It is different for every row

Please help me if you know the solution.

My source is:

    @(Html.Kendo().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Command(command => command.Custom("Name").Text("CustomTextEachRow").Click("ShowRates")).Width(75);
            //columns.Command(command => command.Custom("solicitud").HtmlAttributes(new { actionName = "Edit" }));
            columns.Bound(p => p.ID_SOLICITUDSERVICIO).Visible(false);
            columns.Bound(p => p.NOMBRE_CLIENTE).Title("Cliente");
            columns.Bound(p => p.FECHA_SOLICITOSERVICIO).Format("{0: yyyy-MM-dd HH:mm:ss}").Title("Fecha");
        })
               .DataSource(dataSource => dataSource
                   .Ajax()
                   .Read(read => read.Action("LeerExt_ControlInterno", "Consultas").Data("getParameter"))
                   .Model(model => { model.Id(p => p.ID_SOLICITUDSERVICIO); })
               )
           )

Tags
Grid
Asked by
Arvind
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Misahael
Top achievements
Rank 1
Share this question
or