如何在jqGrid中进行在线编辑时将自定义参数传递给ajax请求 [英] How to pass custom params to ajax request on in-line edit in jqGrid

查看:101
本文介绍了如何在jqGrid中进行在线编辑时将自定义参数传递给ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的jqGrid处理程序.

This is my jqGrid handler.

var myEditParams = {
    keys: true,
    extraparam: {
        ajax: function () {
            alert("in myEditParams:extraparam");
            return "1";
        }
    }
};
var lastsel;
jQuery("#list2").jqGrid({
        data: data,
        height: 250,
        emptyDataText: "No Records Found",
        width: $('#mainwrapper').width(),
        datatype: "local",        
        colNames:['Table Description','Display Table name'],
        colModel:[
            { name:'table_desc', index:'table_desc', sortable: false, align: 'left', editable: true, edittype: 'text', editoptions:{ size:40 }, formatoptions:{
                keys: true,
                editOptions: myEditParams
            } },
            { name:'display_table_name',index:'display_table_name', sortable: false }
        ],
        loadComplete: function(){
            $('.ui-jqgrid-htable').css('width',$('#mainwrapper').width()+'px');
             if ($('#list2').getGridParam('records') == 0){ // are there any records?
                DisplayEmptyText(true);
             }else{
                DisplayEmptyText(false); 
             }                    
        },
        rowNum:10,
        rowList:[10,20,30],
        pager: '#pager2',
        sortname: 'id',
        viewrecords: true,
        sortorder: "desc",
        caption:"Changelog Tables",
        postData: { ajax: "1" },
        onSelectRow: function(id){
            if(id && id!==lastsel){
                jQuery('#list2').jqGrid('restoreRow',lastsel);
                jQuery('#list2').jqGrid('editRow',id,true);
                $('#list2').jqGrid('setGridParam',id,{ ajax:"1" }); //wanted to set some custom params here.
                lastsel=id;
            }
        },
        editurl: "changeLog.php"
    });

当我执行一些就地编辑操作时,我想以ajax = 1的形式发送一个额外的参数.我已经尽力了.但是似乎没有任何作用.我几乎感到沮丧.

I want to send one extra param as ajax=1, when I do some in-place edit operation. I have tried every way. But nothing seems to work. I am almost frustrated.

我尝试过:

$("#list2").jqGrid('setGridParam',{postData:{ajax:'1'}});

没用.正如您在处理程序中看到的那样,我还尝试设置postData参数.那也行不通.这是怎么了?请帮助我

Didn't work. I also tried setting postData param as you can see in the handler. That too is not working. What is going wrong here? Please help me with this

推荐答案

方法 editRow 支持extraparam.因此,您可以这样重写onSelectRow:

The method editRow supports extraparam. So you can rewrite onSelectRow so:

onSelectRow: function (id) {
    var $myGrid = $(this); // it's better as jQuery('#list2')
    if (id && id !== lastsel) {
        $myGrid.jqGrid('restoreRow', lastsel);
        $myGrid.jqGrid('editRow', id, {
            keys: true,
            extraparam: { ajax: "1" }
        });
        lastsel = id;
    }
}

通过这种方式,您可以使用方法(函数)代替extraparam中的属性.在以下情况下可能会非常有用.像extraparam: { ajax: $("#myControl").val() }这样的值将在调用editRow函数时进行计算.如果要使用extraparam: { ajax: function () { return $("#myControl").val(); } },则ajax参数的值将在保存时评估.此时$("#myControl").val()可以具有另一个值.

By the way you can use methods (functions) instead of properties in the extraparam. It can be helfull in the following case. The values like extraparam: { ajax: $("#myControl").val() } will be calculated at the moment of the call the editRow function. If you would be use extraparam: { ajax: function () { return $("#myControl").val(); } } then the value of ajax parameter will be evaluated at the moment of saving of the value. At the moment the $("#myControl").val() can have another value.

这篇关于如何在jqGrid中进行在线编辑时将自定义参数传递给ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆