How to get a jqGrid cell value when editing

前端 未结 23 2523
日久生厌
日久生厌 2020-11-27 17:43

How to get a jqGrid cell value when in-line editing (getcell and getRowData returns the cell content and not the actuall value of the input element).

23条回答
  •  抹茶落季
    2020-11-27 18:20

    This is my solution:

                    function getDataLine(grida, rowid){  //vykradeno z inineeditu a vohackovano
    
                        if(grida.lastIndexOf("#", 0) === 0){
                            grida = $(grida);
                        }else{
                            grida = $("#"+grida);
                        }
    
                        var nm, tmp={}, tmp2={}, tmp3= {}, editable, fr, cv, ind;
    
                        ind = grida.jqGrid("getInd",rowid,true);
                        if(ind === false) {return success;}
                        editable = $(ind).attr("editable");
                        if (editable==="1") {
                            var cm;
                            var colModel = grida.jqGrid("getGridParam","colModel") ;
                            $("td",ind).each(function(i) {
                                // cm = $('#mygrid').p.colModel[i];
                                cm = colModel[i];
                                nm = cm.name;
                                if ( nm != 'cb' && nm != 'subgrid' && cm.editable===true && nm != 'rn' && !$(this).hasClass('not-editable-cell')) {
                                    switch (cm.edittype) {
                                        case "checkbox":
                                            var cbv = ["Yes","No"];
                                            if(cm.editoptions ) {
                                                cbv = cm.editoptions.value.split(":");
                                            }
                                            tmp[nm]=  $("input",this).is(":checked") ? cbv[0] : cbv[1]; 
                                            break;
                                        case 'text':
                                        case 'password':
                                        case 'textarea':
                                        case "button" :
                                            tmp[nm]=$("input, textarea",this).val();
                                            break;
                                        case 'select':
                                            if(!cm.editoptions.multiple) {
                                                tmp[nm] = $("select option:selected",this).val();
                                                tmp2[nm] = $("select option:selected", this).text();
                                            } else {
                                                var sel = $("select",this), selectedText = [];
                                                tmp[nm] = $(sel).val();
                                                if(tmp[nm]) { tmp[nm]= tmp[nm].join(","); } else { tmp[nm] =""; }
                                                $("select option:selected",this).each(
                                                    function(i,selected){
                                                        selectedText[i] = $(selected).text();
                                                    }
                                                );
                                                tmp2[nm] = selectedText.join(",");
                                            }
                                            if(cm.formatter && cm.formatter == 'select') { tmp2={}; }
                                            break;
                                    }
                                }
                            });
                        }
                        return tmp;
                    }
    

提交回复
热议问题