Enable/Disable multiple buttons

4 posts, 1 answers
  1. Grant
    Grant avatar
    41 posts
    Member since:
    Jul 2016

    Posted 27 Jul Link to this post

    Hi,

    I have a table containing 28 dynamically generated KendoUI buttons that represent a 28 day cycle. Im trying to enable and disable them all at once, but only the first button is being affected. Please advise.

    //Inialize ALL 'day selection' buttons
    $("#table-frequencyWindow-daySelection").find("button.dayButton").kendoButton({
      enable: false
    });
     
    //Inialize Frequency Selecter as kendo Drop Down List
    $("#select-frequencyWindow-frequency").kendoDropDownList({
      change: function(e) {
        var daySelectionTable = $("#table-frequencyWindow-daySelection");
        console.log(daySelectionTable.find("button.dayButton").length) //Prints "28"
     
        if (this.value() == "") {
          daySelectionTable.find("button.dayButton").data("kendoButton").enable(false);
     
        } else {
          daySelectionTable.find("button.dayButton").data("kendoButton").enable(true);
        }
      }
    });

  2. Misho
    Admin
    Misho avatar
    129 posts

    Posted 29 Jul Link to this post

    Hi,

    You can use the Kendo button enable() method to control the button Enable/Disable state.
    For multiple buttons you can iterate over the buttons in a loop and set the desired Enable or Disable state according to your needs. Here is a simple example showing the approach:
    http://dojo.telerik.com/@parvanov/eJEZa/8


    Regards,
    Misho
    Telerik by Progress
     
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
     
  3. Kendo UI is VS 2017 Ready
  4. Grant
    Grant avatar
    41 posts
    Member since:
    Jul 2016

    Posted 29 Jul in reply to Misho Link to this post

    Thanks Misho, 

    This is the solution I have also arrived at and have already implemented it with success. Initially I was hoping there would be a way to enable/disable all the buttons at once instead of iterating over each one every time, so I let the question stand. 

    As explained in my question though, when I try to enable/disable the buttons using the previous code, only the first KendoButton in the series is affected. Can you think of any reason why the others would be ignored, just out of curiosity?

    Thanks Again, 

    Grant

  5. Answer
    Misho
    Admin
    Misho avatar
    129 posts

    Posted 02 Aug Link to this post

    Hi,

    You can enable/disable all buttons using jQuery find, which will return an object of elements, together with jQuery each method in the following manner:

    $("#example").find(".k-button").each(function(index)
      {
         $(this).data("kendoButton").enable(false);
      }
    )
    http://dojo.telerik.com/@parvanov/eJEZa/9

    Regards,
    Misho
    Telerik by Progress
     
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
     
Back to Top
Kendo UI is VS 2017 Ready