javascriptjquery-uikendo-uikendo-gridkendo-tabstrip

Kendo UI Tabstrip: Tab should render a grid after clicking on a button inside that tab


I have a tabstrip with two tabs. In the first tab, I have button named "Show grid". After clicking that button it will render a grid along with a back button to go back to the previous view that contained only the "show grid" button. The problem is how can I go back using this back button?

<body>

<div id="tabstrip">
  <ul>
    <li id="tab1">Tab 1</li>
    <li id="tab2">Tab 2</li>
  </ul>
  <div>
    <button class='k-button'>Show grid</button>
    <div id="button1"></div>
    <div id="grid"></div>
  </div>
  <div>Content 2</div>
</div>

<script>


  function grid() {
    $("#grid").kendoGrid({
  columns: [
    { field: "name" },
    { field: "age" }
  ],
  dataSource: {
    data: [
      { name: "Jane Doe", age: 30 },
      { name: "John Doe", age: 33 }
    ]
  }
});
  }

  var tabStrip = $("#tabstrip").kendoTabStrip().data("kendoTabStrip");

   $(".k-button").one("click", function() {
     $("#button1").append('<button>Click</button>');
     grid();
     });

</script>
</body>

Solution

  • Try this , in this example I used the same button, however following the same logic you can create a new one keeping both

    var tabStrip = $("#tabstrip").kendoTabStrip().data("kendoTabStrip");
      var flag = true;
     
    
     
        $("#grid").kendoGrid({
      columns: [
        { field: "name" },
        { field: "age" }
      ],
      dataSource: {
        data: [
          { name: "Jane Doe", age: 30 },
          { name: "John Doe", age: 33 }
        ]
      }
    }).hide();
      
    
      
    $(".k-button").click(function () {
       if(flag === true){
        $("#grid").show();
        $(".k-button").text("Remove grid");
         flag = false;
      } else {
        $("#grid").hide();
        $(".k-button").text("Show grid");
        flag = true;
      }
    });
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>Untitled</title>
    
      <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.common.min.css">
      <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.rtl.min.css">
      <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.default.min.css">
      <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.1017/styles/kendo.mobile.all.min.css">
    
      <script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
      <script src="https://kendo.cdn.telerik.com/2018.3.1017/js/angular.min.js"></script>
      <script src="https://kendo.cdn.telerik.com/2018.3.1017/js/jszip.min.js"></script>
      <script src="https://kendo.cdn.telerik.com/2018.3.1017/js/kendo.all.min.js"></script>
     
      <style>
        .k-edit-form-container { width: 500px;}
        .k-popup-edit-form .k-edit-label { width: 20%; text-align: left; }
        .k-popup-edit-form .k-edit-field { width: 70%; }
        .k-popup-edit-form .k-edit-field > .k-textbox, 
        .k-popup-edit-form .k-edit-field > .k-widget:not(.k-tooltip)
        { width: 98%; }
      </style>
    </head>
    <body>
    
    <div id="tabstrip">
      <ul>
        <li id="tab1">Tab 1</li>
        <li id="tab2">Tab 2</li>
      </ul>
      <div>
        <button class='k-button'>Show grid</button>
        <div id="button1"></div>
        <div id="grid"></div>
      </div>
      <div>Content 2</div>
    </div>
    
    
    </body>
    </html>