Change the button text on command.Custom

2 posts, 0 answers
  1. Russell
    Russell avatar
    3 posts
    Member since:
    Jul 2016

    Posted 18 Nov 2016 Link to this post

    Hello,

    I have a custom command column in my grid as seen below.  I would like to change the text of the button from "Activate" to "Deactivate" based on 2 other cells values in the row.  How can I do this?  Thanks.

    col.Command(command => command.Custom("Activate").Click("activate_deactivate")).Locked(true).Width(140);
  2. Eyup
    Admin
    Eyup avatar
    4075 posts

    Posted 22 Nov 2016 Link to this post

    Hello Russell,

    You can use the items() method of the grid to achieve this requirement:
    http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#methods-items


    For example:
    Copy Code
    columns.Command(command =>
    {
        command.Custom("Creating").Click("CreateOrderCmd")
        .HtmlAttributes(new { @class = "creatingButtonClass" });
    Grid event:
    Copy Code
    .Events(e => e.DataBound("gridDataBound"))
    JavaScript:
    Copy Code
    function gridDataBound(e) {
        var grid = this;
        grid.items().each(function (i, item) {
            var value = grid.dataItem(item).ProductName;
            var button = $(item).find(".creatingButtonClass");
            if (value == "Chang") {
                button.hide();
            }
        });
    }

    Alternatively, you can use Templates with condition:
    http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/faq#how-to-apply-conditional-logic-in-column-client-templates

    I hope this will prove helpful.


    Regards,
    Eyup
    Telerik by Progress
    Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
Back to Top