2012-07-10 112 views
0

我有一个JQGrid有自定义设置来编辑和保存行数据的变化,但我有点困惑。来自我选择的数据不会出现在我的文章中,我可以在编辑更改当前选定行的值并将错误引入编辑过程的行时选择另一行。JQGrid编辑选择和保存

$.ajax({ 
    type: 'POST', 
    url: '/myserver/myservice.asmx/GetMyData', 
    contentType: 'application/json; charset=utf-8', 
    dataType: 'json', 
    data: params 
}).success(function(data) { 
    clearNotSatisifiedConcessionList(); 
    var rowid; 
    var response = data.d; 
    if (response.length > 0) { 
     $('p.infotext').html('<span class="ui-icon ui-icon-info"></span><strong>Information: </strong>Click a row, then click <b><i>Edit</i></b>'); 
     var lastsel2; 
     var grid = $("#myList").jqGrid({ 
      datatype: "local", 
      data: response, 
      height: '100%', 
      autowidth: true, 
      hidegrid: false, 
      ajaxSelectOptions: { type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json' }, 
      colNames: ['ID', 'Date', 'col1', 'col2', 'col3'], 
      colModel: [ 
       { name: 'ID', index: 'ID', width: 20 }, 
       { name: 'Date', index: 'Date', width: 30, sorttype: 'date', formatter: 'date', formatoptions: { srcformat: 'd/m/Y', newformat: 'd/m/Y' }, datefmt: 'd/m/Y' }, 
       { name: 'col1', index: 'col1', width: 20 }, 
       { name: 'col2', index: 'col2', width: 25, sorttype: 'int' }, 
       { name: 'col3', index: 'col3', width: 35, sorttype: 'int' } 
      ], 
      pager: '#MyPager', 
      rowNum: 15, 
      editurl: '/myserver/myservice.asmx/SaveMyData', 
      editData : {"SmodifiedByPersonRef":getCurrentUserPersonRef(), "modifiedByPostRef": getCurrentUserPostRef()}, 
      sortname: 'Date', 
      sortorder: 'desc', 
      viewrecords: true, 
      gridview: true, 
      caption: '' 
     }); 
    } else { 
     clearList(); 
     $('p.infotext').html('<span class="ui-icon ui-icon-info"></span><strong>Information: </strong>No data found'); 
    } 
}).error(function(jqXHR, textStatus, errorThrown) { 
    errorHandler(errorThrown, 'List', 'Load List'); 
}); 

这是我的名单上面我的编辑选择和取消功能

$("#editRow").click(function(event) { 
    event.preventDefault(); 
    var selectedRow = $('#myList').jqGrid('getGridParam', 'selrow'); 
    if (selectedRow === null) { 
     alert('No row Selected!'); 
    }else { 
     $("#myList").jqGrid('editRow', selectedRow); 
     $(".editButton").hide(); 
     $(".saveButton").show(); 
     $(".cancelButton").show();  
    } 
}); 

$("#saveRow").click(function(event) { 
    event.preventDefault(); 
    var selectedRow = $('#myList').jqGrid('getGridParam', 'selrow'); 
    var coincessionId = $("#myList").getCell(selectedRow, "ID"); 
    $("#myList").jqGrid('saveRow', coincessionId); 
    $(".saveButton").hide(); 
    $(".cancelButton").hide(); 
    $(".editButton").show(); 
}); 

$("#cancelEdit").click(function(event) { 
    event.preventDefault(); 
    var selectedRow = $('#myList').jqGrid('getGridParam', 'selrow'); 
    $("#myList").jqGrid('restoreRow', selectedRow); 
    $(".saveButton").hide(); 
    $(".cancelButton").hide(); 
    $(".editButton").show(); 
}); 

有没有人做了一个解决方案类似拖网互联网还没有一个答案给我提供了,任何问题或意见,请请不要犹豫,但请注意,由于此列表将出现在应用程序中,因此此代码有许多编辑。

回答

0

我已经添加了处理程序,在编辑时将rowid添加到窗口变量中,并在取消时检查此变量并保存当前选定的行是最初选择的行,这似乎工作,但是宽松工作