2016-05-12 67 views
0

私は3つの列を持つjQGridを持っています。最初はドロップダウン(タイプ:選択)フィールド、もう1つはチェックボックスリストのカスタムタイプ、3つ目はテキストフィールドです。要件は、ユーザーがドロップダウンフィールド(DocGroupname)の値を変更した後、DocListフィールドが空である必要があります。 DocGroupName列の値を変更するときにDocList列の値を空にする必要があります。JQgrid、別のセルの変更イベントでセル値を空にする

次のようにしてみました。ドロップダウンの値を変更する際に、myfunctionという名前の関数と呼ばれます。DocListカラムの値をnullに設定する関数の内部にあります。しかし、それは動作していない、だから私は間違っていた?誰でも私に解決策を見つけるのを助けてください。

JQGridコード、

function ReqKYCGrid() 
{ 

$("#divmsgg").show(); 

       var DocGroupName = $.ajax 
       ({ 
        type: 'GET', 
        async: false, 
        url: RootUrl + "EXEntityTypeKYC/GetDocumentGroupList", 
        cache: true, 
        contentType: 'application/json; charset=utf-8', 
        data: { "projectSeq":$("#Id").val(),"StartDate":$("#StartDate").val(),"EndDate":$("#EndDate").val() }, 
        success: function (result) { 
         if (!result) alert('No Document Group Found !!'); 
        }, 
        error: function (error) { 
         alert('Error' + error); 
        } 
       }).responseText; 


     jQuery("#grdForReqKYC").jqGrid({ 
     url: RootUrl+ 'EXEntityTypeKYC/ReqKYCGridData', 
     datatype: 'json', 
     mtype: 'POST', 
     colNames: ['id', 'Document Group Name','Document Name','No of Mandatory'], 
     colModel: [ 
        { name: 'id', index: 'id', width: 30, sorttype: "int", editable: false,hidden:true },      
        { name: 'DocGroupName', index: 'DocGroupName', width: 310, editable: true, edittype: "select", editrules: { required: true} , 
        editoptions: { 

         dataInit: function (element) { 
             $(element).focusout(function (e) { 
             if(this.value!="") 
             { 

             } 
             }); 
            }, 

         dataEvents: [{type: 'change', fn: function(e){ 
          myfunction(e); 
          } 
         }]} 

        }, 

        { name: 'DocList', index: 'DocList', width: 310, hidden:false,editable: true,edittype: "custom", editoptions: { dataInit: function (element) { 

             $(element).click(function (e) { 

             }); 
            }, 
        custom_element:MultiCheckElem, custom_value:MultiCheckVal }}, 
        { name: 'Mandatory', index: 'Mandatory', width: 310, editable: true, edittype: "text", editoptions: { maxlength: "1" , dataInit: function (element) { 
           $(element).keydown(function (e,val) { 
           var ctrl = e.ctrlKey; 
            var key = e.charCode || e.keyCode || 0; 
            if (ctrl && ((key == 88) /* CUT */ || (key == 67) /* COPY */ || (key == 86) /* PASTE */)) { return false; 
            } 
            if (e.which != 8 && e.which != 0 && e.which != 46 && (e.which < 48 || e.which > 57)) { 
             return false; 
            } 

            var rowDataObj=$('#grdForReqKYC').jqGrid('getRowData',cellRowId); 
            var rowData =JSON.parse(JSON.stringify(rowDataObj)); 
            var docListValue=rowData["DocList"].split(','); 

            if(((docListValue.length -1)==0) && rowData["DocList"]=='') 
            { 
             alert("Please Choose Document Name"); 
             return false; 
            } 

            if(e["char"]> (docListValue.length)) 
            { 
            return false; 
            } 




           }); 
          }}, editrules: { required: true} } 
        //, list:'Check1,Check2,Check3,Check4' 
       ], 

     loadComplete: function() {  
       if(DocGroupName!=null) 
         $("#grdForReqKYC").setColProp('DocGroupName', { editoptions: { value: JSON.parse(DocGroupName)} }); 

       //if(DocumentName!=null) 
       //alert(DocumentName+ ' ---- '+ JSON.parse(DocumentName)); 
         // $("#grdForReqKYC").setColProp('DocumentName', { editoptions: { value: JSON.parse(DocumentName)} }); 
         //$("#grdForReqKYC").setColProp('DocList', { editoptions: { list: CheckedDocumentName} }); 


     }, 

     cellEdit: true, 
     rowNum: 1000, 
     //gridview: true, 
     rownumbers: true, 
     //autoencode: true,   
     height: 120, 
     width: 700, 
     cellsubmit: 'clientArray', 
     caption: "Required Document for KYC", 
     multiselect: true, 
     // onSelectRow: function(id){alert(id)}, 

     postData: { 
      "MSTSeq": $("#Id").val(), 
      "data": $("#KYCGrid").val() 
     }, 
     onCellSelect: function (rowid, iCol, cellcontent, e) { 
     //alert(rowid); 
     cellRowId=rowid; 
     } 
    }); 


    //End Of Grid 

     $(window).on("resize", function() { 
     var newWidth = $("#grdForReqKYC").closest(".ui-jqgrid").parent().width(); 
     if(newWidth>900) 
     { 
     jQuery("#grdForReqKYC").jqGrid("setGridWidth", 900, true); 

     } 
     else{ 
     jQuery("#grdForReqKYC").jqGrid("setGridWidth", newWidth, true); 
     } 
    }); 

    // Start of AddNew/Delete function for Grid 
    $("#btnAddNew").click(function() { 

     if (ValidateRow($("#grdForReqKYC"))) { 
      var idAddRow = $("#grdForReqKYC").getGridParam("reccount") 
      emptyItem = [{ id: idAddRow + 1, FinancialYearNames: "", EntityName: "", AllocatedValue: "", ProjectDesc: ""}]; 
      jQuery("#grdForReqKYC").jqGrid('addRowData', 0, emptyItem); 
     } 
    }); 


    $("#btnDelete").click(function() { 
     $("#grdForReqKYC").jqGrid("editCell", 0, 0, false); 
     var gr = jQuery("#grdForReqKYC").jqGrid('getGridParam', 'selarrrow'); 
     if (gr != "") { 
      for (var i = 0; i <= gr.length; i++) { 
       jQuery("#grdForReqKYC").jqGrid('delRowData', gr[i]); 
      } 
      for (var i = 0; i <= gr.length; i++) { 
       jQuery("#grdForReqKYC").jqGrid('delRowData', gr[i]); 
      } 
     } 
     else 
      alert("Please Select Row(s) to delete!"); 
    }); 

    // End of AddNew/Delete function for Grid 

} 

MyFunctionのコード、あなたがする必要がどのような

function myfunction(e) 
{ 
    // grid.jqGrid('setCell', 1, 'DocList', '', null, null, true); 
    $("#grdForReqKYC").setColProp('DocList', { editoptions: { formatter: nullFormatter} }); 
} 

function nullFormatter() 
{ 
    return ''; 
} 

答えて

1

はbeforeSaveCell機能 Here上のセルの値を変更ではjsfiddleに私はあなたのために作成したソリューションです。

var currentRow = 0; 

function getAllSelectOptions(){ 
    var states = { '1': 'Alabama', '2': 'California', '3': 'Florida', 
        '4': 'Hawaii', '5': 'London', '6': 'Oxford' }; 

     return states; 

    } 
      validateText = function (value, colname) { 
     // do validations if any and return false    
       return [true]; 
      }; 

      "use strict"; 
      var mydata = [ 
        {id:"1", DocGroupName: "2", DocList: "y", Mandatory: "z"}, 
        {id:"2", DocGroupName: "6", DocList: "y", Mandatory: "z"}, 
       ]; 
      $("#list").jqGrid({ 


       //url:'php.scripts/customers.get.php', 
       //datatype: 'xml', 
       //mtype: 'POST', 
       datatype: "local", 
       data: mydata, 
       height: "auto", 
       colNames: ['id', 'Document Group Name','Document Name','No of Mandatory'], 
       colModel :[ 
        {name:'id', index:'id', width:55}, 
        {name:'DocGroupName', index:'DocGroupName', width:90, editable: true,edittype: 'select', 
              formatter: 'select', 

              editoptions:{value: getAllSelectOptions()}, "editrules":{"custom":true,"custom_func":validateText}}, 
        {name:'DocList', index:'DocList', width:90, editable: true }, 
        {name:'Mandatory', index:'Mandatory', width:90, editable: true} 

       ], 
       pager: '#pager', 
       rowNum:10, 
       rowList:[10,20,30], 
       sortname: 'idcustomers', 
       sortorder: 'asc', 
       viewrecords: true, 
       gridview: true, 
       caption: 'Customers', 
       cellEdit: true, 
       cellsubmit: 'clientArray', 
       afterSaveCell: function(rowid,name,val,iRow,iCol) { 
       if(name=='DocGroupName') 
       { 
        var row = $('#list').jqGrid('getRowData',currentRow);  
        row.DocList=''; 
        $('#list').jqGrid('setRowData',currentRow,row);  
       }     
       }, 
       beforeSaveCell: function(rowid,name,val,iRow,iCol) { 
       // var row = $("#list").getRowData(rowid); 
        var row = $('#list').jqGrid('getRowData',rowid); 
        currentRow= rowid; 

       }, 

}); 
+0

Ameteが祝福@:私は、値を変更し、その後ドキュメントリストが空になった場合、私は、それを試してみましたが、私はドキュメントリストのフィールドは、後DocGroupnameフィールドを変更編集するとき、私は、ドキュメントリストの任意の値を入力することはできません。何をすべきか?? –

+0

@MdAslam私は問題とjsfiddleを修正しました。 afterSaveCellを変更して、どの列が行編集されているかを確認しました。 –

+0

@ Ameteはい、解決策を出しました。本当に、それは私には役に立ちますが、これは適切な解決策ではないため、私のアプリケーションでは使用できません。私は、フィールドを空にした後でフィールドを再度編集することはできないということです。 jsfiddleでコードを確認してください。jsfiddleでも動作していません。たとえば、jsfiddleの 'DocGroup'を変更して 'Docname'をクリックすると、ドキュメント名が空になりますが、これは問題ありませんが、ドキュメント名を編集して、選択した値を保持できない場所をクリックしてください。)Plz jsfiddleでチェックしてください –

関連する問題