Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQGrid编辑选择和保存_Javascript_Jquery_Jqgrid - Fatal编程技术网

Javascript JQGrid编辑选择和保存

Javascript JQGrid编辑选择和保存,javascript,jquery,jqgrid,Javascript,Jquery,Jqgrid,我有一个JQGrid,它有用于编辑和保存行数据更改的自定义设置,但是我有点困惑。“我的选择”中的数据不会出现在我的帖子中,我可以在编辑行时选择另一行,这会更改当前选定行的值,并在编辑过程中引发错误 $.ajax({ type: 'POST', url: '/myserver/myservice.asmx/GetMyData', contentType: 'application/json; charset=utf-8', dataType: 'json',

我有一个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');
});

是否有人做过类似的解决方案,因为拖网互联网尚未向我提供答案,任何问题或评论,请不要犹豫询问,但请考虑到此代码有许多编辑,因为此列表将出现在应用程序的性质中

我添加了一些处理程序,可以在编辑时将rowid添加到窗口变量中,并在取消和保存时检查此变量,确保当前选定的行是最初选定的行。这似乎可行,但是一个松散的解决方法

$("#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();
});