簡體   English   中英

jqGrid-保存內聯編輯不起作用

[英]jqGrid - Saving an Inline Edit not working

我有一個jqGrid,其中使用內聯添加/編輯功能在其中列出了用戶列表。 由於某些原因,我無法讓jqGrid保存我在調用saveEdit函數時所做的編輯,但是如果按enter鍵,數據將被保存。 如果我注釋掉inlineNav行,一切都會按預期進行。

為了明確saveEdit當運行我的saveEdit函數時,沒有任何請求發送到服務器。 當我按Enter鍵時,請求將發送到服務器。 知道發生了什么嗎?

這是我的代碼:

var editParams = {
    afterSubmit: processResponse, 
    successfunc: function(response) {
        var processed = processResponse(response);
        if(processed[0] !== true) {
            $.jgrid.info_dialog($.jgrid.errors.errcap, processed[1], $.jgrid.edit.bClose);
        }
        return processed[0];
    }, 
    bottominfo: 'Fields marked with an (*) are required', 
    keys: true
};
$.extend($.jgrid.edit, editParams);
$('#grid')
    .jqGrid({
        datatype: 'json', 
        colNames: ['User ID', 'First Name', 'Last Name', 'Email'], 
        colModel: [
            {name: 'usr_id', jsonmap: 'usr_id', width: 75, editable: true, editrules: {required: true}, formoptions: {elmprefix: '(*) '}}, 
            {name: 'usr_fname', jsonmap: 'usr_fname', width: 75, editable: true, editrules: {required: true}, formoptions: {elmprefix: '(*) '}}, 
            {name: 'usr_lname', jsonmap: 'usr_lname', width: 75, editable: true, editrules: {required: true}, formoptions: {elmprefix: '(*) '}}, 
            {name: 'usr_email', jsonmap: 'usr_email', width: 125, editable: true, editrules: {required: true}, formoptions: {elmprefix: '(*) '}}
        ], 
        grouping: true, 
        shrinkToFit: false, 
        height: 200, 
        width: 800, 
        rowNum: 20, 
        rowList: [10, 20, 30, 40, 50, 100], 
        repeatitems: false, 
        ignoreCase: true, 
        jsonReader: { repeatitems: false, id: 'usr_id'}, 
        pager: '#grid_pager', 
        url: 'dataurl.php', 
        editurl: 'editurl.php', 
        ondblClickRow: inlineEdit, 
        onSelectRow: saveEdit
    })
    .jqGrid('navGrid', '#users_pager', {add: false, edit: false, del: false, refresh: false, search: false})
    .jqGrid('inlineNav', '#users_pager', {edit: false, save: false, cancel: false}); //If I comment out this line, everything works perfectly

var lastSel;
/* Start editing the row */
function inlineEdit(id, iRow, iCol) {
    $(this).jqGrid('editRow', id, true, function() { focusRow(id, iCol, this); });
}

function focusRow(id, iCol, table) {
    var ele = document.getElementById(id + '_' + table.p.colModel[iCol].name), 
        length = ele.value.length;
    ele.focus();
    if(ele.setSelectionRange) { //IE
        ele.setSelectionRange(length, length);
    }
    else if(ele.createTextRange) {
        var range = ele.createTextRange();
        range.collapse(true);
        range.moveEnd('character', length);
        range.moveStart('character', start);
        range.select();
    }
}

function saveEdit(id) {
    if(id && id != $(this).data('lastSel')) {
        /* Save the last selected row before changing it */
        $(this).jqGrid('saveRow', $(this).data('lastSel'), editParams);
        $(this).data('lastSel', id);
    }
    $(this).data('lastSel', id);
}

預先感謝任何對我有幫助的人。

好哥們,您無論如何都沒有使用inlineNav,為什么您要保留它呢? 其次,當您按Enter鍵時,它不會調用您的saveEdit函數,默認情況下,此功能僅與此類似。

我看到您正在將記錄保存在onSelectRow屬性上,當按Enter鍵時,在進行內聯編輯后,將不會調用該記錄。 您可以將密鑰設置為:false。 按下Enter鍵不會觸發對服務器的請求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM