Reset the Value in Kendo Dropdown List using MVVM Pattern

kendo DropDownList:
 
Kendo dropdownlist is one of the popular widgets in the Kendo UI, which is derived from the class widget,
 
Use below links to get more information about Kendo dropdownlist,
The kendo dropdownlist supports MVVM pattern, let us see how to implement it using MVVM pattern,
 
Code to implement the Kendo dropdownlist using MVVM Pattern
  1. <!DOCTYPE html>    
  2. <html>    
  3. <head>    
  4.     <meta charset="utf-8">    
  5.     <title>Untitled</title>    
  6.     
  7.     <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.406/styles/kendo.common.min.css">    
  8.     <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.406/styles/kendo.rtl.min.css">    
  9.     <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.406/styles/kendo.default.min.css">    
  10.     <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.406/styles/kendo.mobile.all.min.css">    
  11.     
  12.     <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>    
  13.     <script src="http://kendo.cdn.telerik.com/2016.1.406/js/angular.min.js"></script>    
  14.     <script src="http://kendo.cdn.telerik.com/2016.1.406/js/jszip.min.js"></script>    
  15.     <script src="http://kendo.cdn.telerik.com/2016.1.406/js/kendo.all.min.js"></script>    
  16. </head>    
  17. <body>    
  18.     
  19.     <div id="example">    
  20.         <div class="row">    
  21.     
  22.     
  23.             <div class="col-lg-3">    
  24.                     
  25.                     Voting Status:    
  26.                     <input id="VotingStatusList" data-role="dropdownlist"    
  27.                            data-bind="source:votingStatusList,value:VotingStatusList" data-text-field="Text" data-value-field="Value" data-option-label="--Select Voting Status--"    
  28.                            style="width:100%" />    
  29.             </div>    
  30.     
  31.         </div>    
  32.     </div>    
  33.     <script>    
  34.             
  35.     $(document).ready(function(){    
  36.      var viewModel = kendo.observable({    
  37.      VotingStatusList:'',    
  38.          votingStatusList:    
  39.            [{ Text: "Eligible", Value: "1" },    
  40.              { Text: "Not-Eligible", Value: "2" },    
  41.               ]    
  42.               
  43.         });    
  44.     kendo.bind($("#example"), viewModel);    
  45.       })    
  46.     </script>    
  47. </body>    
  48. </html>    
The source property is used to define the data source for the dropdownlist,
 
Reset the value in kendo dropdownlist
 
Using Viewmodel
 
Code to reset the value in Kendo dropdownlist using viewmodel,
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="utf-8">  
  5.     <title>Untitled</title>  
  6.   
  7.     <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.406/styles/kendo.common.min.css">  
  8.     <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.406/styles/kendo.rtl.min.css">  
  9.     <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.406/styles/kendo.default.min.css">  
  10.     <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.406/styles/kendo.mobile.all.min.css">  
  11.   
  12.     <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>  
  13.     <script src="http://kendo.cdn.telerik.com/2016.1.406/js/angular.min.js"></script>  
  14.     <script src="http://kendo.cdn.telerik.com/2016.1.406/js/jszip.min.js"></script>  
  15.     <script src="http://kendo.cdn.telerik.com/2016.1.406/js/kendo.all.min.js"></script>  
  16. </head>  
  17. <body>  
  18.   
  19.     <div id="example">  
  20.         <div class="row">  
  21.   
  22.   
  23.             <div class="col-lg-3">  
  24.                   
  25.                     Voting Status:  
  26.                     <input id="VotingStatusList" data-role="dropdownlist"  
  27.                            data-bind="source:votingStatusList,value:VotingStatusList" data-text-field="Text" data-value-field="Value" data-option-label="--select voting status--"  
  28.                            style="width:100%" />  
  29.                              
  30.             </div>  
  31.                             <br/>  
  32.                            <button data-bind="click:reset" class="k-button">Reset</button>  
  33.         </div>  
  34.     </div>  
  35.     <script>  
  36.           
  37.     $(document).ready(function(){  
  38.      var viewModel = kendo.observable({  
  39.      VotingStatusList:'',  
  40.          votingStatusList:  
  41.            [{ Text: "Eligible", Value: "1" },  
  42.              { Text: "Not-Eligible", Value: "2" },  
  43.               ],  
  44.         reset:function(e)  
  45.         {  
  46.         e.preventDefault();  
  47.         viewModel.set("VotingStatusList",-1);  
  48.         },    
  49.         });  
  50.           
  51.     kendo.bind($("#example"), viewModel);  
  52.       })  
  53.     </script>  
  54. </body>  
  55. </html>  
The reset function is triggered on button click which is used to reset the value of the dropdownlist value by setting the VotingStatusList model to -1.
 
 
I hope you enjoyed this blog. Your valuable feedback, question, or comments about this blog are always welcomed.
X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now