保存回调函数后的jQgrid

时间:2013-01-14 11:45:27

标签: javascript jquery jqgrid

我创建了一个jQgrid,并希望它在添加新行或在网格中编辑某些内容后调用回调函数

jQuery("#list1").jqGrid({
        url: '/testGrid/sample?q=5', 
        datatype: "json", 
        mtype: 'POST',
        jsonReader: {
            page: "page",
            total: "total",
            root: "rows",
            records: "records",
            repeatitems: false,
            cell: "name",
            userdata: 'userdata'
        },
        width: 775,
          colNames: ['Salaried Employees', '# of FTEs', 'Budget', 'Actuals to Date', 'Invoice Salary'],
          colModel: [
            {name:'salEmp',index:'salEmp', width:100, align: 'left', width:100,editable:false,editrules:{required:true}},
            {name:'FTE',index:'FTE', width:100, align: 'center', editable:false,required:true,editrules:{required:true,number:true}},
            {name:'Budget',index:'Budget', width:100, align: 'right', width:100,editable:false,required:true,editrules:{required:true,number:true}},
            {name:'actDate',index:'actDate', width:100, align: 'right', align:"right",editable:false,required:true,editrules:{required:true,number:true}},
            {name:'invSal',index:'invSal', width:100, align:"right",editable:true,required:true,editrules:{required:true,number:true}}                                        
           ],
            rowNum: 5,
            rowList: [5, 10, 20],
            autoencode: true,
            ignoreCase: true,
            sortable: false,
            height: '100%',
            pager: jQuery('#pager1'),
            cellEdit: false,
            cellsubmit: 'remote',
            //cellurl: '/testGrid/sample',

            //call onclick of save
            editurl:"/testGrid/sample",
            gridview: true,
            reloadAfterSubmit:true
        })
        // Pager options for Subgrid
        .navGrid('#pager1',{
            add:false,
            edit:false,
            del:true,
            search:false,
            refresh:false,
            deltext: 'Delete'
        });
$('#list1').jqGrid('inlineNav','#pager1',{
            addtext: "Add",
            edittext: "Edit",
            savetext: "Save",
            canceltext: "Cancel",                       
            addParams: { 
                position: "afterSelected"
            },
            addedrow:'last'

        });

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:8)

inlineNav允许指定用于内联编辑的editRow回调。要指定回调,可以使用editParamsaddParams.addRowParams选项:

var myEditOptions = {
        keys: true,
        oneditfunc: function (rowid) {
            alert("row with rowid=" + rowid + " is editing.");
        },
        aftersavefunc: function (rowid, response, options) {
            alert("row with rowid=" + rowid + " is successfuly modified.");
        }
    };

$('#list1').jqGrid('inlineNav','#pager1', {
    addtext: "Add",
    edittext: "Edit",
    savetext: "Save",
    canceltext: "Cancel",                       
    addParams: { 
        position: "afterSelected",
        addRowParams: myEditOptions
    },
    addedrow: "last",
    editParams: myEditOptions
});