Remove all row from kedno grid.

by Rikin Patel

HTML

<script src="http://cdn.kendostatic.com/2012.3.1114/js/kendo.all.min.js"></script>
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.3.1114/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.3.1114/styles/kendo.default.min.css">
 <div>
     <button type="button" id="removeallrow">Remove All Rows</button>
     <button type="button" id="add">Load Data</button>
     <div id="Grid"></div>
</div>

JavaScript

$("#Grid").kendoGrid({     
     dataSource: {
         data: [
             { "Dept": "ACT", "A": 10, "B": 2010, "Total": 7542 },
             { "Dept": "BCT", "A": 20, "B": 2010, "Total": 7542 },
             { "Dept": "CCT", "A": 20, "B": 2010, "Total": 7542 },
             { "Dept": "CCT", "A": 20, "B": 2010, "Total": 7542 }
         ]
     },
     columns: [{
         field: "Dept",
         title: "Dapartment"
     }, {
         field: "A"
     }, {
         field: "B"
     }, {
         field: "Total"
     }
    ],
    sortable: {
      allowUnsort: false,
      mode: "single"
    }
 });

function removeallrow()
{
    
 //$("#Grid").data('kendoGrid').dataSource.data([]);   
}

$("#removeallrow").click( function()
           {
           var grid = $("#Grid").data('kendoGrid');           
           grid.dataSource.data([]); 
           grid.setDataSource([]);
           
           }
        );


$("#add").click( function()
           {
           
           var dataSource = new kendo.data.DataSource({
  data: [
             { "Dept": "ACT", "A": 10, "B": 2010, "Total": 7542 },
             { "Dept": "BCT", "A": 20, "B": 2010, "Total": 7542 },
             { "Dept": "CCT", "A": 20, "B": 2010, "Total": 7542 },
             { "Dept": "CCT", "A": 20, "B": 2010, "Total": 7542 }
         ]
});

         var grid = $("#Grid").data('kendoGrid');         
           grid.setDataSource(dataSource);
           }
        );