jqGrid:多次调用'添加'失败

时间:2014-07-31 22:52:25

标签: jquery jqgrid

初次加载时,内置"添加"只要模态对话框未被取消,函数就会按预期工作。但是,取消对话后,调用"添加"导致为搜索参数POST一个空字段(在本例中为' name')。

jQuery(document).ready(function(){
    var s = {};
    jQuery("#taggrid").jqGrid({
        jsonReader : {root:"gridModel"},
        url:"jsonGridTag.action",
        datatype:"json",
        mtype:"POST",
        colNames:['tag_id','name','usage count'],
        colModel:[
            {name:'id',index:'id',sortable:true,search:false},
            {name:'name',index:'name',width:400,editable:true,edittype:"text",sortable:true,search:true,searchoptions:{sopt:['cn','eq','bw','ew']}},
            {name:'count',index:'count',formatter:"formatLink",sortable:true,search:true,searchoptions:{sopt:['eq','ne','lt','gt']}}
        ],
        rowNum:300,
        rowList:[300,1000,5000,10000],
        sortname:'name',
        sortorder:'asc',
        sortableRows:true,
        caption:'Tags',
        gridview:true,
        pager:'#pager',
       toppager:true,
        loadonce:false,
        editurl:'jsonGridTagEdit.action',
        cellurl:'jsonGridTagEdit.action',
        cellEdit:false,
        multiselect:true,
        viewrecords:true
    });
    jQuery("#taggrid").jqGrid('navGrid','#pager',{
        edit:true,
        add:true,
        del:true,
        refresh:true,
        view:true,
        search:true,
        cloneToTop:true,
    });
};

问题很明显,不是解决方案......

1 个答案:

答案 0 :(得分:0)

如果您在发送额外数据时遇到问题,则必须在onclickSubmit事件上实现,如下所示:

$("#taggrid").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,search:false,refresh:true},        
    {}, //edit options        
    //add options   
    { 
        url:"../Controller?action=editUser", // CHANGE TO YOUR URL
        closeAfterEdit:true,
        reloadAfterSubmit:true,
        onclickSubmit: function(params, postdata) {
            // here, jqGrid will automatically send these fields to your Servlet (if you're using java): id, name and count. They came from colModel.   
            // if you want to send extra data to your Servlet, you must send it on return like this:
            return {
                another_field: VALUE,
                one_more_field: VALUE
            }
        }
    },      
    {}, //del options
    {}, //search options
    {} //refresh options

您可以在this link

上查看有关jqGrid事件的更多信息