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

C# run powershell script as administrator

Recently I was fetching a problem that I need to run a PowerShell script that will change TFS user Display name and SID. I was trying to run that script from C# that was not working due to TFS security update and TLS certificate. Using this code block I resolve the Issue. var newProcessInfo = new System.Diagnostics.ProcessStartInfo(); newProcessInfo.FileName = @"C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe"; newProcessInfo.Verb = "runas"; // Define Run as administrator newProcessInfo.Arguments = script; //Define your powershell script newProcessInfo.UseShellExecute = false; newProcessInfo.RedirectStandardOutput = true; // This will enable to read Powershell run output newProcessInfo.RedirectStandardError = true; Process proces = System.Diagnostics.Process.Start(newProcessInfo); proces.WaitForExit(); // I want to read the output string from powershell window StringBuilder output = new StringBuilder(); output.Append("Started"); while (!proces.St

ASP.NET MVC razor SAP Crystal report

Crete a new project: Add a aspx Master Page Create a new folder Reports and 2 sub folder crystal & crystalviewer Now add a web form page in crystalviewer  folder. Add the master page namespace in your web form page. MasterPageFile ="~/Views/Shared/ReportSite.Master" Replace your web form by this code < asp : Content ID ="Content1" ContentPlaceHolderID ="ContentPlaceHolder1" runat ="server">      </ asp : Content > Now go to design mode of your web form drag & drop the crystal report viewer in your web form. After that your page will be look look like this. Replace the code: < CR : CrystalReportViewer ID ="EmployeeList" runat ="server"   HasCrystalLogo ="False"     AutoDataBind ="True"   Height ="50px"   EnableParameterPrompt ="false" EnableDatabaseLogonPrompt

mvc razor textboxfor change event change another textboxfor value

Based on value of Weight, Rate , CNF & AWB it will change the value of Freight , TTLCNF anfd TTLFright . Freight= Weight*Rate; TTLCNF  = Weight*CNF; TTLFright=  Freight+ TTLCNF  + AWB; @Html.TextBoxFor(model => model.Weight, new { onChange="return GetWight(this);"}) @Html.TextBoxFor(model => model.Rate, new { onChange="return GetWight(this);"})/Kg @Html.TextBoxFor(model => model.Freight, new {disabled = "disabled" , @readonly = "readonly" ,onChange="return GetTTLFright(this);"}) @Html.TextBoxFor(model => model.CNFPK, new { onChange="return GetCNFPK(this);"}) @Html.TextBoxFor(model => model.TTLCNF, new {disabled = "disabled" , @readonly = "readonly",onChange="return GetTTLFright(this);" }) @Html.TextBoxFor(model => model.AWB, new { onChange="return GetTTLFright(this);"}) and script <script> function GetW