jQuery UI Widgets Forums Grid get dropdown id instead for display name on change event of dependent dropdowns

This topic contains 4 replies, has 2 voices, and was last updated by  sureshatpure 9 years, 2 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author

  • sureshatpure
    Participant

    Hi Dimitar,
    I have two dropdown dependent values Status and Substatus
    initially when i add a row i populate the lead status based on the value in “Lead id” column, if no lead id is there
    then i populate all the lead status in the Status column
    now when i change the value of the Status, in the cellvaluechanging function when i try to alert i get the statusname (i mean the name of the status – Prospect or Met the Customer…or so…. ) instead i want to alert the id’s of these status.. how can these be done..
    id Statusname
    == ===========
    1 Prospect
    2 Met the customer
    3 Credit Assessment
    4 Sample,Trails & Formalities
    5 Enquiry/Offer/Negotiation
    6 Managing And Implementation

    Sample code..
    =============

    {text: 'Status', datafield: 'statusid', width: 150, cellsalign: 'center', cellbeginedit:Results.initResultsEditorldst, initeditor: Results.resultsEditorldst, cellsrenderer: Results.renderUnitsldst,promptText:'Select Status',
                                                            cellvaluechanging: function (row, datafield, columntype, oldvalue, newvalue) 
                                                            {
                                                                
                                                                alert("oldvalue "+oldvalue); alert("newvalue "+newvalue);
    
                                                              //  alert("datafield "+datafield); 
                                                                  if (newvalue == 0) {
                                                                        return oldvalue;
                                                                    }
                                                                    else if (newvalue!=oldvalue)
                                                                    {
                                                                       $("#jqxgrid_add").jqxGrid('setcellvalue', row, "leadsubstatusid", "Select Substatus");
                                                                        return newvalue;
                                                                    } 
    
                                                            }
                                            },

    Full Code
    ==========

    $("#jqxgrid_add").jqxGrid(
                                    {
                                        height: 200,
                                        selectionmode: 'rowselect',
                                        source: dataAdapterAdd,
                                        theme: theme,
                                        editable: true,
                                        columnsresize: true,
                                        columns: [
                                            {text: 'UID', datafield: 'uid', width: 150, cellsalign: 'left', hidden: true},
                                            {text: 'Customer Group', datafield: 'custgroup', width: 100, editable: false},
                                            {text: 'Cust Id', datafield: 'id', width: 100, editable: false},
                                            {text: 'Product Group', datafield: 'itemgroup', width: 150, cellsalign: 'left', editable: false},   
                                            {text: 'Prod Id', datafield: 'itemid', width: 100, editable: false},
                                            {text: 'Lead id', datafield: 'leadid', displayfield: 'leadid', width: 127, cellsalign: 'center', cellbeginedit:Results.initResultsEditor, initeditor: Results.resultsEditor, cellsrenderer: Results.renderUnits,promptText:'Select Leadid',
                                                            cellvaluechanging: function (row, datafield, columntype, oldvalue, newvalue) 
                                                            {
                                                                //alert("oldvalue "+oldvalue); alert("newvalue "+newvalue);
                                                                  if (newvalue == 0) {
                                                                   return oldvalue;
                                                              } 
    
                                                            }
    
                                              
                                            },
                                                
    
                                            {text: 'noofleads', datafield: 'noofleads', hidden:false, width: 20, cellsalign: 'left', editable: false},
                                            {text: 'result_type', datafield: 'result_type',hidden:false, width: 75, cellsalign: 'left', editable: false},
                                            { text: 'Create Lead', datafield: 'create_lead', hidden:false, width: 20, cellsalign: 'left', editable: false},
                                            {text: 'Activity Type', datafield: 'Sub_Activity', width: 110, cellsalign: 'left', cellbeginedit:Results.initResultsEditorat, initeditor: Results.resultsEditorat, cellsrenderer: Results.renderUnitsat
                                            },
                                            {text: 'Potential', datafield: 'Potential_Quantity', width: 75, cellsalign: 'left', editable: false},
                                            {text: 'Required Quantity', datafield: 'Quantity_Requirement', width: 75, cellsalign: 'left',
                                                cellbeginedit: function (row, datafield, columntype) {
                                                            var rowdata = $("#jqxgrid_add").jqxGrid('getrowdata', row);
                                                            var leadid = rowdata.leadid;
                                                           // alert("leadid in quantity cell rendering "+leadid);
                                                            if(leadid==undefined || leadid==0)
                                                            {
                                                                return true;
                                                            }
                                                            else
                                                            {
                                                                return false;
                                                            }
    
                                                        }
                                            },
                                            {text: 'Sales Type', datafield: 'division', width: 110, cellsalign: 'left',readonly:true,cellbeginedit:Results.initResultsEditorst, initeditor: Results.resultsEditorst, cellsrenderer: Results.renderUnitsst
                                           
                                            },
                                            {text: 'Status', datafield: 'statusid', width: 150, cellsalign: 'center', cellbeginedit:Results.initResultsEditorldst, initeditor: Results.resultsEditorldst, cellsrenderer: Results.renderUnitsldst,promptText:'Select Status',
                                                            cellvaluechanging: function (row, datafield, columntype, oldvalue, newvalue) 
                                                            {
                                                                
                                                                alert("oldvalue "+oldvalue); alert("newvalue "+newvalue);
    
                                                              //  alert("datafield "+datafield); 
                                                                  if (newvalue == 0) {
                                                                        return oldvalue;
                                                                    }
                                                                    else if (newvalue!=oldvalue)
                                                                    {
                                                                       $("#jqxgrid_add").jqxGrid('setcellvalue', row, "leadsubstatusid", "Select Substatus");
                                                                        return newvalue;
                                                                    } 
    
                                                            }
                                            },
                                            {text: 'SubStatus', datafield: 'leadsubstatusid', width: 200, cellsalign: 'left',readonly:false,cellbeginedit:Results.initResultsEditorldsubst, initeditor: Results.resultsEditorldsubst, cellsrenderer: Results.renderUnitsldsubst,cellvaluechanging: function (row, datafield, columntype, oldvalue, newvalue) 
                                                        {
                                                           // alert("oldvalue "+oldvalue); alert("newvalue "+newvalue);
                                                              if (newvalue == 0)  {
                                                               return oldvalue;
                                                          } 
                                                           else if (newvalue!=oldvalue)
                                                           {
    
                                                             if(newvalue=='Appointment Fixed')
                                                             {
                                                                
                                                                $("#appiontment_date").val(null);                                       
                                                                $("#popupWindow").jqxWindow('show');
                                                                $("#save_appdt").click(function (event){
                                                                       
                                                                        var date_text = $('#appiontment_date').jqxDateTimeInput('getText');
                                                                        if(date_text=="")
                                                                        {
                                                                            alert("Please select the Appointment Date");
                                                                            return false;
                                                                        }
                                                                        else
                                                                        {
    
                                                                             $("#jqxgrid_add").jqxGrid('setcellvalue', jqxgrid_add_row_index, "appiontmnt_dt",date_text);
                                                                            $("#popupWindow").jqxWindow('close');
                                                                        }
                                                                   
                                                                });
                                                                
                                                             }
                                                             /*Not able to get appointment start*/
                                                              if(newvalue=='Not Able to get the Appointment')
                                                             {
                                                                
                                                                                                      
                                                                $("#popupWindowNot").jqxWindow('show');
                                                                $("#save_na2gappdt").click(function (event){
                                                                
                                                                        var reason_text = $('#not_able_to_get_appointment').val();
                                                                        if(reason_text=="")
                                                                        {
                                                                            alert("Please Enter the Reason");
                                                                            return false;
                                                                        }
                                                                        else
                                                                        {
    
                                                                             $("#jqxgrid_add").jqxGrid('setcellvalue', jqxgrid_add_row_index, "not_able_to_get_appointment",reason_text);
                                                                            $("#popupWindowNot").jqxWindow('close');
                                                                        }
                                                                   
                                                                });
                                                                
                                                             }
                                                             /* Not able to get appointment end*/
                                                             return newvalue;
                                                           }
    
                                                        }
                                           
                                            },
                                            {text: 'Apptmnt Date', datafield: 'appiontmnt_dt', columntype:'datetimeinput', width: 110, align: 'left', cellsformat: 'd',formatString: 'dd/MM/yyyy',readonly:true,editable:false, hidden:false},
    
                                            {text: 'Not Able', datafield: 'not_able_to_get_appointment', width: 110, align: 'left', hidden:true, editable:false},
    
                                            {text: 'Mode of Contact', datafield: 'Mode_Of_Contact', width: 100, cellsalign: 'left', cellbeginedit:Results.initResultsEditorcon, initeditor: Results.resultsEditorcon, cellsrenderer: Results.renderUnitsst
                                            },
                                            {text: 'Time Spent (Hrs)', datafield: 'hour', width: 75, cellsalign: 'left', columntype: 'dropdownlist',
                                                createeditor: function (row, cellvalue, editor) {
                                                    editor.jqxDropDownList({source: ["00 Hr", "01 Hrs", "02 Hrs", "03 Hrs", "04 Hrs", "05 Hrs", "06 Hrs", "07 Hrs", "08 Hrs", "09 Hrs", "10 Hrs"]});
                                                }
                                            },
                                            {text: 'Time Spent (Mins)', datafield: 'minute', width: 75, cellsalign: 'left', columntype: 'dropdownlist',
                                                createeditor: function (row, cellvalue, editor) {
                                                    editor.jqxDropDownList({source: ["0 mins", "5 mins", "10 mins", " 15 mins", "20 mins", "25 mins", "30 mins", " 35 mins", "40 mins", "45 mins", " 50 mins", "55 mins"]});
                                                }
                                            },
                                            {text: 'Notes / Remarks', datafield: 'Notes_Remarks', width: 150, cellsalign: 'left'},
    
                                        ]
    
                                    });

    Corresponding functions.

    var  Results ={
    
                                   initResultsEditor: function(row){
    
                                      var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                      //alert("item group "+data.itemgroup);
                                      if(data.itemgroup==undefined)
                                      {
                                      //  alert("yes");
                                        data.result_type='Value';
                                      }
                                      
                                      if(data.result_type === 'Value')
                                        {
                                            this.columntype = 'textbox';
                                        } 
    
                                       else if(data.result_type === 'Select') 
                                       {
                                        this.columntype = 'dropdownlist';
                                       }
                                   },
    
                                   initResultsEditorat: function(row){
                                      var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                      if(data.result_type === 'Value')
                                        {
                                            this.columntype = 'dropdownlist';
    
                                        } 
    
                                       else if(data.result_type === 'Select') 
                                       {
                                        this.columntype = 'dropdownlist';
                                       // return false;
                                       }
                                   },
                                   initResultsEditorst: function(row){
                                      var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                      if(data.result_type === 'Value')
                                        {
                                            
                                              this.columntype ='dropdownlist';
    
                                        } 
    
                                       else if(data.result_type ==='Select') 
                                       {
                                        this.columntype='textbox';
                                        return false;
    
                                       }
                                   },
                                   initResultsEditorldst: function(row){
                                      var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                      if(data.result_type === 'Value')
                                        {
                                              this.columntype ='dropdownlist';
                                        } 
    
                                       else if(data.result_type ==='Select') 
                                       {
                                          this.columntype ='dropdownlist';
                                       // return false;
    
                                       }
                                   },
    
                                   initResultsEditorldsubst: function(row){
                                      var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                      if(data.result_type === 'Value')
                                        {
                                            
                                              this.columntype ='dropdownlist';
    
                                        } 
    
                                       else if(data.result_type ==='Select') 
                                       {
                                        this.columntype='dropdownlist';
                                      //  return false;
    
                                       }
                                   },
    
                                   
                                   initResultsEditorcon: function(row){
                                      var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                      if(data.result_type === 'Value')
                                        {
                                            
                                              this.columntype ='dropdownlist';
                                        } 
    
                                       else if(data.result_type ==='Select') 
                                       {
                                        this.columntype='textbox';
                                        return false;
                                       }
                                   },
                                   resultsEditor: function(row, cellvalue, editor){
                                      var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                       var cust_grp = $('#jqxgrid_add').jqxGrid('getcellvalue', row, "custgroup");
                                       var prod_grp = $('#jqxgrid_add').jqxGrid('getcellvalue', row, "itemgroup");
                                      switch(data.result_type){
                                         case 'Value':
                                           editor.jqxInput({ placeHolder: "No Leads" });
                                           $.ajax({
                                                    type: "POST",
                                                    url: base_url + 'dailyactivity/checkduplicate_product/'+encodeURIComponent(cust_grp)+"/"+encodeURIComponent(prod_grp),
                                                    data: 'prodgroup=' + encodeURIComponent(prod_grp) + '&customergroup=' + encodeURIComponent(cust_grp),
                                                    dataType: 'json',
                                                    success: function (response)
                                                    {
    
                                                        if (response.ok == false)
                                                        {
                                                            //  datevalidation=false;
                                                            //validateProductName.html(response.msg);
                                                                 //alert("This product group has been already billed for this customer")
                                                                 validateProductName.html(response.msg);
                                                                // editor.jqxCheckBox({ checked: false, hasThreeStates:false});
                                                                $("#jqxgrid_add").jqxGrid('setcellvalue', jqxgrid_add_row_index, "create_lead",0);
                                                        }
                                                        else
                                                        {
                                                            // datevalidation=true;
                                                            validateProductName.html(response.msg);
                                                            $("#jqxgrid_add").jqxGrid('setcellvalue', jqxgrid_add_row_index, "create_lead",1);
                                                        }
    
                                                    }
                                                })
                                         break;
                                         case 'Select':
    
                                         
                                                var list = {
                                                    datatype: "json",
                                                    datafields:
                                                            [
                                                                {name: 'id'},
                                                                {name: 'leadid'}
                                                            ],
                                                    id: 'id',
                                                    root: "leadid",
                                                    url: base_url + "dailyactivity/getleadids/"+encodeURIComponent(cust_grp)+"/"+encodeURIComponent(prod_grp),
                                                    cache: false,
                                                    async: false
                                                   
                                                };
    
                                                listdataAdapter = new $.jqx.dataAdapter(list, {
                                                    autoBind: true,
                                                    buildSelect: function (suboptions)
                                                    {
                                                        
                                                         console.log(suboptions);
                                                        var data = new Array();
                                                        $.each(suboptions, function (id, value)
                                                        {
                                                            var list = records[i];
                                                            list.id = list.id;
                                                            list.leadid = list.leadid;
                                                            data.push(list);
                                                        });
                                                        return data;
                                                    }
                                                });
                                        
                                        
                                            editor.jqxDropDownList(
                                                {
                                                    source: listdataAdapter.records, displayMember: "id",autoDropDownHeight: true, valueMember: "leadid",promptText:"No Leads",selectedIndex:1,placeHolder: 'Select Leadid',renderer: function (index, label, value) 
                                                        {
                                                        //alert("value "+value);
                                                        var hrefUrl = base_url+'leads/viewleaddetails/' + value;
                                                        var option = '<div value="' + value + '"><a href="' + hrefUrl + '" target="_blank">' + value + '</a></div>';
                                                               return option;
                                                            
                                                        }
                                                });
    
                                                  
                                                 
                                         break;
                                         case 'Cascaded':
                                         break;
                                         default:
                                            alert('Unbound result type.... I dont know how to handle this!!!');
                                         break;
                                      }
                        
                                   },
                                   resultsEditorst: function(row, cellvalue, editor){
                                       var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                     //  var data.leadid = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                      
                                     var leadid =data.leadid;
                                      switch(data.result_type){
                                         case 'Value':
                                           editor.jqxDropDownList(
                                            {source: ["Tanker", "Repacked", "Container", "Textile", "Leather", "Paper", "Exxon Speciality", "Lubricant", "Polymer", "Pure Speciality", "Others"]
                                            });
                                         break;
                                         case 'Select':
    
                                            } // end of switch
                                                
                                   },
                                   resultsEditorldst: function(row, cellvalue, editor){
                                       var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                       var leadid =data.leadid;
                                      // alert("leadid in resultsEditorldst "+leadid);
                                       if (leadid!="")
                                        {
                                            geturl=base_url + "dailyactivity/getldstatusfor/"+leadid;
                                        }
                                        else
                                        {
                                            geturl=base_url + "dailyactivity/getldstatus";
                                            
                                        }
                                       var stslist = {
                                                    datatype: "json",
                                                    datafields:
                                                            [
                                                                {name: 'statusid'},
                                                                {name: 'statusname'}
                                                            ],
                                                    id: 'statusid',
                                                    root: "statusid",
                                                    url: geturl,
                                                    cache: false,
                                                    async: false
                                                   
                                                };
    
                                                stslistdataAdapter = new $.jqx.dataAdapter(stslist, {
                                                    autoBind: true,
                                                    buildSelect: function (suboptions)
                                                    {
                                                        
                                                         console.log(suboptions);
                                                        var data = new Array();
                                                        $.each(suboptions, function (id, value)
                                                        {
                                                            var stslist = records[i];
                                                            stslist.statusid = list.statusid;
                                                            stslist.statusname = stslist.statusname;
                                                            data.push(stslist);
                                                        });
                                                        return data;
                                                    }
                                                });
                                        
                                        
                                            editor.jqxDropDownList(
                                                {
                                                    source: stslistdataAdapter.records, displayMember: "statusname",autoDropDownHeight: true, valueMember: "statusid",promptText:"Status",selectedIndex:0,placeHolder: 'Select status',renderer: function (index, label, value) 
                                                        {
                                                             var option = '<div value="' + value + '">' + label + '</div>';
                                                               return option;
                                                        }
                                                });
                                   },
                                   resultsEditorldsubst: function(row, cellvalue, editor){
                                       var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                       alert(data.toSource());
                                       var status_name = data.statusid;
                                       var leadid =data.leadid;
                                       alert("in initeditor addform substatus "+status_name);
                                        if (leadid!="")
                                        {
                                          //  geturl=base_url + "dailyactivity/getldsubstatusforlead/"+leadid;
                                          geturl=base_url + "dailyactivity/getldsubstatusbynameid/"+status_name+"/"+leadid;
                                        }
                                        else
                                        {
                                            geturl=base_url + "dailyactivity/getldsubstatusbyname/"+status_name;
                                            
                                        }
                                       var substslist = {
                                                    datatype: "json",
                                                    datafields:
                                                            [
                                                                {name: 'substatusid'},
                                                                {name: 'substatusname'}
                                                            ],
                                                    id: 'substatusid',
                                                    root: "substatusid",
                                                    /*url: base_url + "dailyactivity/getldsubstatus",*/
                                                    /*url: base_url + "dailyactivity/getldsubstatusbyname/"+status_name,*/
                                                     url: geturl,
                                                    cache: false,
                                                    async: false
                                                   
                                                };
    
                                                substslistdataAdapter = new $.jqx.dataAdapter(substslist, {
                                                    autoBind: true,
                                                    buildSelect: function (suboptions)
                                                    {
                                                        
                                                         console.log(suboptions);
                                                        var data = new Array();
                                                        $.each(suboptions, function (id, value)
                                                        {
                                                            var substslist = records[i];
                                                            substslist.substatusid = list.substatusid;
                                                            substslist.substatusname = substslist.substatusname;
                                                            data.push(substslist);
                                                        });
                                                        return data;
                                                    }
                                                });
                                        
                                        
                                            editor.jqxDropDownList(
                                                {
                                                    source: substslistdataAdapter.records, displayMember: "substatusname",autoDropDownHeight: true, valueMember: "substatusid",promptText:"SubStatus",selectedIndex:0,placeHolder: 'Select substatus',renderer: function (index, label, value) 
                                                        {
                                                             var option = '<div value="' + value + '">' + label + '</div>';
                                                               return option;
                                                        }
                                                });
                                                
                                   },
                                   resultsEditorcon: function(row, cellvalue, editor){
    
                                       var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                     //  var data.leadid = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                      
                                     var leadid =data.leadid;
                                      switch(data.result_type){
                                         case 'Value':
                                           editor.jqxDropDownList(
                                            {source: ["E-mail", "Phone", "Visit"],autoDropDownHeight: true
                                            });
                                         break;
                                         case 'Select':
    
                                            } // end of switch
                                                
                                   },
                                   resultsEditorat: function(row, cellvalue, editor){
                                       var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                     //  var data.leadid = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                             
                                      switch(data.result_type){
                                         case 'Value':
                                           editor.jqxDropDownList(
                                            {source: ["NEW CUSTOEMR", "EXSISTING CUSTOMER", "ORDER FOLLOWUP", "ORDER AND PAYMENT", "TENDER", "PAYMENT FOLLOW UP", "BALANCE SHEET", "TANKER  DIVERTION", "INVOICE", "PROFORM INVOICE", "PAYMENT COLLECTION"]
                                            });
                                         break;
                                         case 'Select':
                                             editor.jqxDropDownList({source: ["LEADS"],autoDropDownHeight: true,selectedIndex: 0});
                                     }           
                                   },
                                   renderUnits: function(row, columnfield, value, defaulthtml, columnproperties)
                                   {
                                      var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                      if(data.result_type === 'Value' && data.result !== ''){
                                        
                                         defaulthtml = defaulthtml.replace(/>.+<\/div>/ , '>No Leads</div>');
                                    
                                     }
                                      return defaulthtml;
                                   },
    
                                   renderUnitsat: function(row, columnfield, value, defaulthtml, columnproperties)
                                   {
                     
    
                                      var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                      if(data.result_type === 'Select' && data.result !== '')
                                      {
    
                                         defaulthtml = defaulthtml.replace(/>.+<\/div>/ , '>LEADS</div>');
                        
    
                                     }
                                   
                                      return defaulthtml;
                                   },
                                   renderUnitsst: function(row, columnfield, value, defaulthtml, columnproperties){
                                    
                                      var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                      if(data.result_type === 'Select'){
                                         defaulthtml = defaulthtml.replace(/>.+<\/div>/ , '>'+ value +'</div>');
    
                                     }
                                    
                                      return defaulthtml;
                                   },
                                   renderUnitsldst: function(row, columnfield, value, defaulthtml, columnproperties){
                                      var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                      /*if(data.result_type === 'Select'){
                                         defaulthtml = defaulthtml.replace(/>.+<\/div>/ , '>'+ value +'</div>');
    
                                     }*/
                                     defaulthtml = defaulthtml.replace(/>.+<\/div>/ , '>'+ value +'</div>');
                                    
                                      return defaulthtml;
                                   },
                                   renderUnitsldsubst: function(row, columnfield, value, defaulthtml, columnproperties){
                                      var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
                                     /* if(data.result_type === 'Select'){
                                         defaulthtml = defaulthtml.replace(/>.+<\/div>/ , '>'+ value +'</div>');
    
                                     }*/
                                      defaulthtml = defaulthtml.replace(/>.+<\/div>/ , '>'+ value +'</div>');
                                      return defaulthtml;
                                   }
                                   
                                  
                                  };

    Dimitar
    Participant

    Hi sureshatpure,

    In cellvaluechanging you can access the values of other columns of the same row with getcellvalue, e.g.:

    {
        text: 'Status',
        datafield: 'statusid',
        width: 150,
        cellsalign: 'center',
        cellbeginedit: Results.initResultsEditorldst,
        initeditor: Results.resultsEditorldst,
        cellsrenderer: Results.renderUnitsldst,
        promptText: 'Select Status',
        cellvaluechanging: function(row, datafield, columntype, oldvalue, newvalue) {
    
            alert("oldvalue " + oldvalue);
            alert("newvalue " + newvalue);
    
            var uid = $('#jqxgrid_add').jqxGrid('getcellvalue', row, "uid");
            alert('UID: ' + uid);
    
            //  alert("datafield "+datafield); 
            if (newvalue == 0) {
                return oldvalue;
            } else if (newvalue != oldvalue) {
                $("#jqxgrid_add").jqxGrid('setcellvalue', row, "leadsubstatusid", "Select Substatus");
                return newvalue;
            }
    
        }
    },

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/


    sureshatpure
    Participant

    Hi Dimitar,
    i tried adding this code..but i still get the Statusname only in the alert

    id Statusname
    == =========
    1 Prospect
    2 Met the customer
    3 Credit Assessment
    4 Sample,Trails & Formalities
    5 Enquiry/Offer/Negotiation
    6 Managing And Implementation

    {text: 'Status', datafield: 'statusid', width: 150, cellsalign: 'center', cellbeginedit:Results.initResultsEditorldst, initeditor: Results.resultsEditorldst, cellsrenderer: Results.renderUnitsldst,promptText:'Select Status',
                                                            cellvaluechanging: function (row, datafield, columntype, oldvalue, newvalue) 
                                                            {
                                                                
                                                                alert("oldvalue "+oldvalue); alert("newvalue "+newvalue);
    
                                                              //  alert("datafield "+datafield); 
                                                               var sid = $('#jqxgrid_add').jqxGrid('getcellvalue', row, "statusid");
                                                               alert('statusid: ' + sid);
    
                                                                  if (newvalue == 0) {
                                                                        return oldvalue;
                                                                    }
                                                                    else if (newvalue!=oldvalue)
                                                                    {
                                                                       $("#jqxgrid_add").jqxGrid('setcellvalue', row, "leadsubstatusid", "Select Substatus");
                                                                        return newvalue;
                                                                    } 
    
                                                            }
                                            },
    

    Dimitar
    Participant

    Hi sureshatpure,

    The behaviour you describe means that your “Status” column displays the Statusnames, not the ids. If this is so, are the ids displayed in some other column? If not, you can try the following:

    var statusNames = ['Prospect', 'Met the customer', 'Credit Assessment', 'Sample,Trails & Formalities', 'Enquiry/Offer/Negotiation', 'Managing And Implementation'];
    
    ...
    
    {
        text: 'Status',
        datafield: 'statusid',
        width: 150,
        cellsalign: 'center',
        cellbeginedit: Results.initResultsEditorldst,
        initeditor: Results.resultsEditorldst,
        cellsrenderer: Results.renderUnitsldst,
        promptText: 'Select Status',
        cellvaluechanging: function(row, datafield, columntype, oldvalue, newvalue) {
            var oldId = statusNames.indexOf(oldvalue) + 1;
            var newId = statusNames.indexOf(newvalue) + 1;
    
            alert("oldvalue " + oldId);
            alert("newvalue " + newId);
    
            var uid = $('#jqxgrid_add').jqxGrid('getcellvalue', row, "uid");
            alert('UID: ' + uid);
    
            //  alert("datafield "+datafield); 
            if (newvalue == 0) {
                return oldvalue;
            } else if (newvalue != oldvalue) {
                $("#jqxgrid_add").jqxGrid('setcellvalue', row, "leadsubstatusid", "Select Substatus");
                return newvalue;
            }
    
        }
    },

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/


    sureshatpure
    Participant

    Hi Dimitar,
    Anyway will check out your code and update ( as you had said i am not storing the status id’s in any other column )

    Meanwhile,You can see that i use the following code to update the dropdown with Statusname along with their id’s
    Which is fetched from the database using this function
    geturl=base_url + "dailyactivity/getldstatus";
    which gives me the result array as

    statusid statusname
    ======== ==========
    1 Prospect
    2 Met the customer
    3 Credit Assessment
    4 Sample,Trails & Formalities
    5 Enquiry/Offer/Negotiation
    6 Managing And Implementation
    and i bind these values using the below code.

    
    resultsEditorldst: function(row, cellvalue, editor){
       var data = $('#jqxgrid_add').jqxGrid('getrowdata', row);
       var leadid =data.leadid;
      // alert("leadid in resultsEditorldst "+leadid);
       if (leadid!="")
        {
            geturl=base_url + "dailyactivity/getldstatusfor/"+leadid;
        }
        else
        {
            geturl=base_url + "dailyactivity/getldstatus";
            
        }
       var stslist = {
                    datatype: "json",
                    datafields:
                            [
                                {name: 'statusid'},
                                {name: 'statusname'}
                            ],
                    id: 'statusid',
                    root: "statusid",
                    url: geturl,
                    cache: false,
                    async: false
                   
                };
    
                stslistdataAdapter = new $.jqx.dataAdapter(stslist, {
                    autoBind: true,
                    buildSelect: function (suboptions)
                    {
                        
                         console.log(suboptions);
                        var data = new Array();
                        $.each(suboptions, function (id, value)
                        {
                            var stslist = records[i];
                        <strong>    
                            stslist.statusid = list.statusid;
                            stslist.statusname = stslist.statusname;
                       </strong>
                            data.push(stslist);
                        });
                        return data;
                    }
                });
        
        
            editor.jqxDropDownList(
                {
                    source: stslistdataAdapter.records, displayMember: "statusname",autoDropDownHeight: true, valueMember: "statusid",promptText:"Status",selectedIndex:0,placeHolder: 'Select status',renderer: function (index, label, value) 
                        {
                             var option = '<div value="' + value + '">' + label + '</div>';
                               return option;
                        }
                });
    },
    
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.