Skip to main content

kendo grid checkbox check validation

In the following above image i want to transfer from left side grid data to right side grid & only the selected grid item. I will check that
- The left grid can check more than one checkbox
- right side grid will check only one.
- left & right side selection item will not same.

Then all the selected check box in the left side will get for right side person for save or update as you want.

Transfer button click:


 <button type="submit" class="btn btn-mini btn-primary" onclick="AccountsManagerTransferResponsiblity()">  
           <i class="icon-retweet"></i>Transfer  
         </button>  

Script:


  function AccountsManagerTransferResponsiblity() {  
     var gridData1 = $("#CustomerAccountManagerKendoGrid1").data("kendoGrid").dataSource.data();  
     var gridData2 = $("#CustomerAccountManagerKendoGrid2").data("kendoGrid").dataSource.data();  
     if (!CheckGridConstraint(gridData1, gridData2)) return;  
     // var gEmpID1 = GetSelectedEmpID(gridData1);  
     // Get selected grid value   
     var gEmpID2 = GetSelectedEmpID(gridData2);  
     //get the grid from left side   
      var gridData = $("#CustomerAccountManagerKendoGrid1").data("kendoGrid").dataSource.data();  
     // set model data   
      for (var i = 0; i < gridData.length; i++) {  
      }  
     var postUrl;  
     var paramValue;  
     // Your controller action path  
     postUrl = '@Url.Content("~/Billing/CustomerAccountManage/AccountsManagerTransferResponsiblityAction")';  
     paramValue = JSON.stringify(  
     {  
       'pEmpID1': gEmpID1  
       , 'pEmpID2': gEmpID2  
       , ManagerList: gridData // passing the grid value in controller as parameter  
     });  
     $.ajax({  
       url: postUrl,  
       type: 'POST',  
       dataType: 'json',  
       data: paramValue,  
       contentType: 'application/json; charset=utf-8',  
       success: function (result) {  
         console.log(result);  
       },  
       error: function (objAjaxRequest, strError) {  
         var respText = objAjaxRequest.responseText;  
         console.log(respText);  
       }  
     });  
   }  


Validation Script:


  function CheckGridConstraint(gridData1, gridData2) {  
     if (!CheckMultipleSelection(gridData1, gridData2)) {  
       return false;  
     }  
     if (!CheckSameEmployeeSelect(gridData1, gridData2)) {  
       alert("Please select different employee to TransferResponsiblity");  
       return false;  
     }  
     return true;  
   }  
   function CheckMultipleSelection(gridData1, gridData2) {  
     var gridCheckCount = 0;  
     //for (var i = 0; i < gridData1.length; i++) {  
     //  if (gridData1[i].SelectStatus == true) {  
     //    gridCheckCount += 1;  
     //  }  
     //}  
     if (gridCheckCount > 1) {  
       alert("Please select one record for left grid");  
       return false;  
     }  
     gridCheckCount = 0;  
     for (var i = 0; i < gridData2.length; i++) {  
       if (gridData2[i].SelectStatus == true) {  
         gridCheckCount += 1;  
       }  
     }  
     if (gridCheckCount > 1) {  
       alert("Please select one record for right grid");  
       return false;  
     }  
     return true;  
   }  
   function CheckSameEmployeeSelect(gridData1, gridData2) {  
     var gd1EmpID;  
     var gd2EmpID;  
     for (var i = 0; i < gridData1.length; i++) {  
       if (gridData1[i].SelectStatus == true) {  
         gd1EmpID = gridData1[i].GEmployeeGenInfoID;  
         for (var j = 0; j < gridData2.length; j++) {  
           if (gridData2[i].SelectStatus == true) {  
             gd2EmpID = gridData2[j].GEmployeeGenInfoID;  
             if (gd1EmpID == gd2EmpID) {  
               return false;  
             }  
           }  
         }  
       }  
     }  
     return true;  
   }  

Get right side single check value:


  function GetSelectedEmpID(gridData) {  
     for (var i = 0; i < gridData.length; i++) {  
       if (gridData[i].SelectStatus == true) {  
         return gridData[i].GEmployeeGenInfoID;  
       }  
     }  
   }  

Get value in controller:


   public ActionResult AccountsManagerTransferResponsiblityAction(string pEmpID1, string pEmpID2, CustomerAccountManagerViewModel _CustomerAccountManagemodel)  
     {  
       var strMessage = string.Empty;  
       Guid EmpID1 = new Guid(pEmpID1);  
       Guid EmpID2 = new Guid(pEmpID2);  
       DateTime TodayDate = DateTime.Now;  
       try  
       {  
         foreach (var item in _CustomerAccountManagemodel.ManagerList.Where(m => m.SelectStatus == true))  
         {  
           IList<DJBL_tblCustomerAccountManagerAssignRelease> listCustomerAccountManagerAssign1 = _billingCommonservice.BillingUnit.CustomerAccountManagerAssignReleaseRepository.Get(d => d.GEmployeeGenInfoID == item.GEmployeeGenInfoID).ToList();  
           DJBL_tblCustomerAccountManagerAssignRelease custAssRelease = null;  
           // Assign Release Insert  
           foreach (var CustAssignRelease in listCustomerAccountManagerAssign1)  
           {  
             custAssRelease = new DJBL_tblCustomerAccountManagerAssignRelease();  
             custAssRelease.CustomerAccountManagerAssignReleaseID = Guid.NewGuid();  
             custAssRelease.CustomerID = CustAssignRelease.CustomerID;  
             custAssRelease.GEmployeeGenInfoID = EmpID2;  
             custAssRelease.AssignDate = TodayDate;  
             custAssRelease.BooketID = CustAssignRelease.BooketID;  
             custAssRelease.ReleaseDate = null;  
             _billingCommonservice.BillingUnit.CustomerAccountManagerAssignReleaseRepository.Add(custAssRelease);  
           }  
           //Assign Release Update   
           foreach (var am in listCustomerAccountManagerAssign1)  
           {  
             am.ReleaseDate = TodayDate;  
             _billingCommonservice.BillingUnit.CustomerAccountManagerAssignReleaseRepository.Update(am, "CustomerAccountManagerAssignReleaseID");  
           }  
           //Transfer responsiblity Insert   
           foreach (var transfer in listCustomerAccountManagerAssign1)  
           {  
             SaveCustomerAccountManagerTransferResponsiblityHistory((Guid)transfer.GEmployeeGenInfoID, EmpID2, TodayDate, (Guid)transfer.BooketID);  
           }  
           _billingCommonservice.BillingUnit.CustomerAccountManagerAssignReleaseRepository.SaveChanges();  
         }  
         return Content(Boolean.TrueString);  
       }  
       catch (Exception ex)  
       {  
         strMessage = CommonExceptionMessage.GetExceptionMessage(ex, CommonAction.Save);  
       }  
       return Content(strMessage);  
     }  


Both Grid binding same i just share one grid binding:


 $("#CustomerAccountManagerKendoGrid1").kendoGrid({  
     dataSource: {  
       transport: {  
         read: "CustomerAccountManageRead"  
       },  
       schema: {  
         model: {  
           fields: {  
             CustomerAccountManageID: { type: "string" },  
             GEmployeeGenInfoID: { type: "string", editable: false },  
             ManagerName: { type: "string", editable: false },  
             SelectStatus: { type: "boolean" },  
           }  
         }  
       },  
       pageSize: 20,  
       serverPaging: false,  
       serverFiltering: false,  
       serverSorting: false,  
     },  
     height: 300,  
     filterable: true,  
     //groupable: true,  
     sortable: true,  
     resizable: true,  
     selectable: true,  
     editable: true,  
     pageable:  
     {  
       refresh: true,  
       pageSizes: [10, 20, 40, 60, 80, 100]  
     },  
     columns:  
     [  
       { field: "SelectStatus", title: " ", width: "5%", template: "<input type='checkbox' #= SelectStatus ? checked='checked':'' # class='chkbx' />" },  
       { field: "CustomerAccountManageID", title: "CustomerAccountManageID", hidden: true, filterable: false, sortable: false },  
       { field: "GEmployeeGenInfoID", title: "GEmployeeGenInfoID", hidden: true, filterable: false, sortable: false },  
       { field: "ManagerName", title: "Manager Name", width: "35%" },  
     ]  
   });  

Grid load:


  public JsonResult CustomerAccountManageRead()  
     {  
       var models = CustomerAccountManage();  
       return Json(models, JsonRequestBehavior.AllowGet);  
     }     


  private List<AssignManagerViewModel> CustomerAccountManage()  
     {  
       IList<DJBL_uspGetAllAssignManager_Result> dataList = null;  
       dataList = _billingCommonservice.BillingUnit.FunctionRepository.AssignManagerValue().ToList();  
       List<AssignManagerViewModel> seriesList = new List<AssignManagerViewModel>();  
       foreach (var md in dataList)  
       {  
         AssignManagerViewModel obj = new AssignManagerViewModel();  
         obj.GEmployeeGenInfoID = md.GEmployeeGenInfoID ?? Guid.Empty;  
         obj.ManagerName = md.ManagerName;  
         obj.ManagerDesignation = md.ManagerDesignation;  
         obj.ManagerDepartment = md.ManagerDepartment;  
         obj.ManagerEmpID = md.ManagerEmpID;  
         obj.ManagerEmpCardNo = md.ManagerEmpCardNo;  
         obj.NoOfCustomer = Convert.ToInt32(md.NoOfCustomer);  
         seriesList.Add(obj);  
       }  
       var PackageInfoInfoViewModels = seriesList.Select(  
         md => new AssignManagerViewModel  
              {  
                GEmployeeGenInfoID = md.GEmployeeGenInfoID,  
                ManagerName = md.ManagerName,  
                ManagerDesignation = md.ManagerDesignation,  
                ManagerDepartment = md.ManagerDepartment,  
                ManagerEmpID = md.ManagerEmpID,  
                ManagerEmpCardNo = md.ManagerEmpCardNo,  
                NoOfCustomer = md.NoOfCustomer,  
                ActionLink = Common.KendoUIGridActionLinkGenerate("Billing", "CustomerAccountManage", md.GEmployeeGenInfoID.ToString(), true, true, false)  
              }).OrderBy(o => o.ManagerName).ThenBy(ot => ot.ManagerEmpID);  
       return PackageInfoInfoViewModels.ToList();  
     }  


Thank you.


Comments

Popular posts from this blog

The calling thread must be STA, because many UI components require this.

Using Thread: // Create a thread Thread newWindowThread = new Thread(new ThreadStart(() => { // You can use your code // Create and show the Window FaxImageLoad obj = new FaxImageLoad(destination); obj.Show(); // Start the Dispatcher Processing System.Windows.Threading.Dispatcher.Run(); })); // Set the apartment state newWindowThread.SetApartmentState(ApartmentState.STA); // Make the thread a background thread newWindowThread.IsBackground = true; // Start the thread newWindowThread.Start(); Using Task and Thread: // Creating Task Pool, Each task will work asyn and as an indivisual thread component Task[] tasks = new Task[3]; // Control drug data disc UI load optimize tasks[0] = Task.Run(() => { //This will handle the ui thread :The calling thread must be STA, because many U...

WPF Crystal Report Viewer Using SAP

There is no doubt that we fall a great problem that the VS2010 is not intregated crystal report. Initially it seems to be a big problem. Hare is some step for SAP crystal report that we can use in our WPF application. 1.Download  Crystal report from this Link: http://scn.sap.com/docs/DOC-7824 2 . Remove Crystal report if any exist. 3. Close your VS-2010 and install the new downloaded CRforVS_13_0 . 4. Take a new WPF project   5. Right click on the project click on Properties 6. Change the target framework .NET Framework 4 Client Profile to  .NET Framework 4. 7. Click on main window then click on Toolbox.  Right Click on the General Tab then click on Choose Item. 8. It will appear this window click on WPF Component. 9.  Select CrystalReportsViewer  click on ok   Button. 10. Now you will see the report viewer control. 11. Your Crystal Report Environment is ready. Now we will a...

SQL Query Execution time of you in SQL Management Studio

You can check the Execution time of you SQL Query in SQL Management Studio. like this It is very simple that you just put your SQL Query in to the Estimated time execution query DECLARE @StartTime datetime DECLARE @EndTime datetime SELECT @StartTime=GETDATE() -- Write Your Query SELECT @EndTime=GETDATE() --This will return execution time of your query SELECT DATEDIFF(NS,@StartTime,@EndTime) AS [Duration in millisecs]