URDINESH: November 2015

Software Programming, Tutorials, Interview Preparations,Stock Market,BSE/NSE, General informations

Tuesday, November 10, 2015

KENDO GRID GET SELECTED ROWS USING CHECKBOX

To get the selected rows from Kendo Grid checkbox Please follow steps mentioned below,


1. Add one Boolean data type value to the entity that we are binding to Kendo Grid,(i.e. boolean property to the class)

    

    I.E. => Boolean  Selected {get;set;}

2. In the View( i.e. .cshtml page) Define the checkbox column as follows using template property of kendo grid,

 Columns.Template(@<text><text>).clientTemplate( "<input type='checkbox'  #= Selected?
                                                    checked= 'checked' ; '' # class = 'chkbxclass'/>");    

3. In the script file corresponding to the view , under           
     $(document).ready function write the following,
   
     function(){
                       $('#gvGridID').on('click','.chkbxclass',
                       function(){
                            var checked = $(this).is(':checked');
                            var grid = $('#gvGridID').data().kendogrid;
                            var dataItem = grid.dataItem($(this).closest('tr'));
                            dataItem.set('Selected',checked);
                          })
                  })
NOTE: "gvGridID"  is the Kendo Grid ID
4. On the submit button click, get the values from the kendo grid by using the following JQuery function,
        
             var grid = $('#gvGridID').data("kendogrid");
              $("#gvGridID tbody").find('tr').each(
                          function() {
                             var dataItem = grid.dataItem($(this).closest('tr'));
                             if(dataItem.Selected == true)
                                {
                                   // Write your logic here like concat all values                                    // with comma separated and store it in                                              // hidden field
                                }
                                            });

Hope this solution will help u to resolve the selecting rows from kendo grid Thanks please give your valuable comments


Followers