2017-09-10 5 views
0

작동하는 dataInit에서 ajax 호출을 통해 데이터를로드하고 모든 것이 올바르게 작동하지만 내 열 (드롭 다운 열만)은 id 값을 설정하지 않습니다.jqGrid onchange (C# MVC)를 선택하지 않음

itemId 및 itemCode 속성이 있습니다. 데이터를로드하고 올바르게 표시하지만 드롭 다운 값을 변경하면 itemId 값을 바인딩하거나 업데이트하지 않습니다.

본질적으로 드롭 다운을 내 ID 열에 바인딩하여 저장할 때 저장할 ID를 얻습니다.

,{ 
        key: false, 
        hidden: true, 
        name: 'itemId', 
        index: 'itemId', 
        editable: false 
       }, { 
        key: false, 
        name: 'itemCode', 
        index: 'itemId', 
        editable: true, 
        edittype: 'select', 
        editoptions: { 
         dataInit: function(element) { 
          $.ajax({ 
           url: '@Url.Action("GetItems", "Maintenance")', 
           dataType: 'json', 
           type: 'POST', 
           success: function(response) { 
            var array = response; 
            if (array != null) { 
             var i; 
             for (i in array) { 
              if (array.hasOwnProperty(i)) { 
               if (itemId == array[i].id) { 
                $(element).append("<option value=" + 
                 array[i].id + 
                 " selected>" + 
                 array[i].code + 
                 "</option>"); 
               } else { 
                $(element).append("<option value=" + 
                 array[i].id + 
                 ">" + 
                 array[i].code + 
                 "</option>"); 
               } 
              } 
             } 
            } 
           } 
          }); 
         } 
        }, 
        editrules: { required: true} 

답변

0

여기 내 대답은 ..... 데이터 이벤트를보십시오. 선택한 행을 찾은 다음 셀을 설정합니다. 콘솔 로그는 그냥 테스트했습니다.

{ 
        key: false, 
        hidden: true, 
        name: 'userId', 
        index: 'userId', 
        editable: false 
       }, { 
        key: false, 
        name: 'userName', 
        index: 'userName', 
        editable: true, 
        edittype: 'select', 
        editoptions: { 
         dataInit: function(element) { 
          $.ajax({ 
           url: '@Url.Action("GetUsers", "Maintenance")', 
           dataType: 'json', 
           type: 'POST', 
           success: function(response) { 
            var array = response; 
            if (array != null) { 
             var i; 
             for (i in array) { 
              if (array.hasOwnProperty(i)) { 
               if (userId == array[i].id) { 
                $(element).append("<option value=" + 
                 array[i].id + 
                 " selected>" + 
                 array[i].userName + 
                 "</option>"); 
               } else { 
                $(element).append("<option value=" + 
                 array[i].id + 
                 ">" + 
                 array[i].userName + 
                 "</option>"); 
               } 
              } 
             } 
            } 
           } 
          }); 
         }, 
         dataEvents: [ 
          { type: 'change', 
           fn: function (e) { 
            var rowId = $("#jqgrid").jqGrid('getGridParam', 'selrow'); 
            $('#jqgrid').jqGrid('setCell', rowId, 'userId', $(e.target).val()); 
            console.log($("#jqgrid").jqGrid('getCell', rowId, 'userId')); 
           } 
          } 
         ] 
        }