Kendo UI with JQuery change template: <input> to readonly or disable

Viewed 1605
  <td role="gridcell">input</td>
  <td role="gridcell">1</td>
  <td role="gridcell">
    <input class="remove1" type="button" value="▼" style="margin: 4px">
    <input id="Txt_test" class="txtBox" type="textbox" value="220" style="margin: 4px">
    <input class="Add1" type="button" value="▲" style="margin: 4px">   
    </td>
  <td style="display:none" role="gridcell">
  </td>
    
  </tr>
  <tr class="k-alt" role="row">
    <td role="gridcell">input</td>
    <td role="gridcell">2</td><td role="gridcell">
    <input class="remove1" type="button" value="▼" style="margin: 4px">
    <input id="Txt_test" class="txtBox" type="textbox" value="59" style="margin: 4px">
    <input class="Add1" type="button" value="▲" style="margin: 4px">
      
    </td>
    </tr>
      
    </tbody> 

top was my out put Html

Then i using JQuery to change below code to disable or readonly but it didn't work!

<input id="Txt_test" class="txtBox" type="textbox" value="220" style="margin: 4px">

I Try on kendo Ui with JQuery

$("#Txt_test").attr('disabled', true);

and

$("#Txt_test").prop('readonly', true);

and change class

$(".txtBox").attr('disabled', true);

I have change input type="text" same error for me. also I try

var clearAddGrid = $("#AddGrid").data('kendoGrid');
clearAddGrid.editable = false;

I want achieve like below

if(status==0)
{
    Grid input can edit
}else{
    Grid input can't edit
}

and this is my grid cells

{ field: "txtRealNum", title: "RealNum", width: "40px", template: '<input class="remove1" type="button" value="▼" style="margin: 1px" /><input  id="Txt_test" class="txtBox" type="textbox" value= #=txtRealNum# style="margin: 4px" /><input  class="Add1" type="button" value="▲" style="margin: 1px" />' },

my grid

    $("#AddGrid").kendoGrid({
        dataSource: AddGriddataSource,
        selectable: "row",
        scrollable: false,
        columns: AddGridCells,
        change: numberInput,
        pageable: {
            buttonCount: 3,
            messages: GridPageMsg
        },
        height: '100%',
        editable: true
    }).data("kendoGrid");
3 Answers

So you want to disabled this?

<input id="Txt_test" class="txtBox" type="textbox" value="220" style="margin: 4px">

Since you are using Kendo UI for jQuery, you can do this:

$("#Txt_test").addClass("k-state-disabled");

That should do it.

Thanks for the example in the Telerik DOJO. If you want to disable all the input text boxes. Add the line below after your Kendo Grid initialization.

$(".txtBox1").addClass("k-state-disabled");

For your convenience:

<!DOCTYPE html>
<html>
<head>
    <base href="https://demos.telerik.com/kendo-ui/grid/from-table">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2021.2.511/styles/kendo.default-v2.min.css" />

    <script src="https://kendo.cdn.telerik.com/2021.2.511/js/jquery.min.js"></script>
    
    
    <script src="https://kendo.cdn.telerik.com/2021.2.511/js/kendo.all.min.js"></script>
    
    

</head>
<body>
    <div id="AddGrid" style="height: 100%;" data-role="grid" class="k-grid k-widget">
      <table role="grid" data-role="selectable" class="k-selectable" style="height: auto;">          <colgroup>
        <col style="width:20px">
        <col style="width:20px">
        <col style="width:30px">
        <col style="width:30px">
        <col style="width:20px">
        </colgroup>
        <thead class="k-grid-header" role="rowgroup">
          <tr role="row">
            <th role="columnheader" data-field="txtRawNo" data-title="no" class="k-header">no</th><th role="columnheader" data-field="txtRawName" data-title="Name" class="k-header">name</th>
            <th role="columnheader" data-field="txtUnit" data-title="U" class="k-header">U</th>
            <th role="columnheader" data-field="txtBookNum" data-title="U" class="k-header">SNUM</th>
            <th role="columnheader" data-field="txtTranNum" data-title="NUM" class="k-header">NUM</th>
            <th role="columnheader" data-field="txtVersion" data-title="Version" style="display:none" class="k-header">Version</th>
          </tr>
        </thead>
        <tbody role="rowgroup"><tr data-uid="130d7d37-64f4-4f6e-98ca-fb2293e8d6ab" role="row">
          <td role="gridcell">11007109-2</td><td role="gridcell">SB 1kg*10</td>
          <td role="gridcell">1000g</td><td role="gridcell">818</td>
          <td role="gridcell"><input id="Del" class="Del1" type="button" value="▼" style="margin: 1px">
            <input id="Txt_test1" class="txtBox1" type="textbox" value="5" style="margin: 4px"><input id="plus" class="plus1" type="button" value="▲" style="margin: 1px">
          </td>
          <td style="display:none" role="gridcell">2021-06-02T15:08:00</td>
          </tr>
          <tr class="k-alt" data-uid="85651f08-df24-40b2-ae05-94123efb3125" role="row">
            <td role="gridcell">11094184</td><td role="gridcell">MS 1kg*10</td>
            <td role="gridcell">1000g</td>
            <td role="gridcell">801</td>
            <td role="gridcell">
              <input id="Del" class="Del1" type="button" value="▼" style="margin: 1px">
              <input id="Txt_test1" class="txtBox1" type="textbox" value="15" style="margin: 4px"><input id="plus" class="plus1" type="button" value="▲" style="margin: 1px"></td>
            <td style="display:none" role="gridcell">2021-06-03T11:24:00</td>
          </tr>
        </tbody>
      </table>
      <div class="k-pager-wrap k-grid-pager k-widget" data-role="pager">
        <a href="#" title="Go to the first page" class="k-link k-pager-nav k-pager-first k-state-disabled" data-page="1" tabindex="-1">
          <span class="k-icon k-i-seek-w">Go to the first page</span>
        </a><a href="#" title="Go to the previous page" class="k-link k-pager-nav k-state-disabled" data-page="1" tabindex="-1">
        <span class="k-icon k-i-arrow-w">Go to the previous page</span></a>
        <ul class="k-pager-numbers k-reset">
          <li><span class="k-state-selected">1</span></li></ul>
        <a href="#" title="Go to the next page" class="k-link k-pager-nav k-state-disabled" data-page="1" tabindex="-1">
          <span class="k-icon k-i-arrow-e">Go to the next page</span></a>
        <a href="#" title="Go to the last page" class="k-link k-pager-nav k-pager-last k-state-disabled" data-page="1" tabindex="-1">
          <span class="k-icon k-i-seek-e">Go to the last page</span></a>
        <span class="k-pager-info k-label">page1-2,total 2</span></div></div>
        </tbody>
    </table>

    <script>
        $(document).ready(function() {
            $("#grid").kendoGrid({
                selectable: "row",
                height: 550,
                sortable: true,
                editable: true
            });
          
            $(".txtBox1").addClass("k-state-disabled"); // comment/uncomment to see the outcome
        });    
     
    </script>
</div>

    

</body>
</html>

Make all inputs with class "txtBox" as kendo component and disable it

$(".txtBox1").kendoTextBox({
       enable: false
});

Based on upper example: Disable inputs

You should change the code to this :

$("#Txt_test").attr('disabled', 'disabled');
Related