本文介绍了如何在使用内联编辑时在jqgrid中发布静态值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向服务器发布一个静态值,类似这样< input type =hiddenname =table_namevalue =<?php echo $ table_name;?> >
该值不是colmodel的一部分,我想在内联编辑发生时发布它,这是我的jqgrid的php文件,

i want to post a static value to server, something like this <input type="hidden" name="table_name" value="<?php echo $table_name; ?>">the value is not a part of colmodel, i want to post it whenever the inline edit happens, this is my php file with jqgrid,

<head>
<script type="text/ecmascript" src="jq/jquery.min.js"></script>
<script type="text/ecmascript" src="jq/jquery.jqGrid.min.js"></script>
<script type="text/ecmascript" src="jq/grid.locale-en.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="jq/jquery-ui.css"/>
<link rel="stylesheet" type="text/css" media="screen" href="jq/ui.jqgrid.css"/>
<meta charset="utf-8" />
</head>
<body>
<table id="rowed5"></table>
<script type="text/javascript">
var lastsel2
var mydata=<?PHP echo $json_data;?>;
jQuery("#rowed5").jqGrid({
    postData: {test_value:'<?PHP echo $table?>'},
    serializeCellData: function( post_to_server ) {
        var postParams  =  jQuery("#rowed5").jqGrid('getGridParam','postData');
        if(postParams.hasOwnProperty('test_value') ) {
            post_to_server['test_value'] = postParams.test_value;
        }
        return post_to_server;
    },
    datatype: "local",
    shrinkToFit: false,
    data: mydata,
    height: 320,
    autowidth:true,
    colNames:['RowID','status','note','Variant ID'],
    colModel:[
        {name:'id',index:'id', width:55, sorttype:"int",align:"center"},
        {name:'status',index:'status', width:150,align:"left", editable: true,
edittype:"select",editoptions:{value:"Exclude:Exclude"}},
        {name:'note',index:'note', width:200, sortable:false,editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"10"}},
        {name:'v_id',index:'v_id', width:150,align:"left"}],
    /*onSelectRow: function(id){
        if(id && id!==lastsel2){
            jQuery('#rowed5').jqGrid('restoreRow',lastsel2);
            jQuery('#rowed5').jqGrid('editRow',id,true);
            lastsel2=id;
        }
    },*/
    editurl: "functions.php",
    cellEdit : true,
    cellsubmit : 'remote',
    cellurl : 'functions.php',
});
jQuery("#rowed5").jqGrid('filterToolbar', {stringResult: true, searchOnEnter: false, defaultSearch : "cn"});
</script>
</body>

我可以发布colmodel值,如:

i am able to post the colmodel values like:

if($_POST['oper']=='edit')
{
    $id = mysql_real_escape_string($_POST['id']);
}

但我想发布一个不属于colmodel的静态值。

but i want to to post a static value which is not a part of colmodel.

错误
未捕获TypeError:jQuery(...)。jqGrid不是函数
at HTMLTableElement.serializeCellData(cam.php:224)
at HTMLTableElement.serializeFeedback(jquery.jqGrid.src.js:2278)
at HTMLTableElement。< anonymous> (jquery.jqGrid.src.js:8478)
at Function.each(jquery.min.js:2)
at n.fn.init.each(jquery.min.js:2)
at n.fn.init.saveCell(jquery.jqGrid.src.js:8403)
at n.fn.init。$。fn.jqGrid(jquery.jqGrid.src.js:2643)$在HTMLSelectElement上的b $ b。< anonymous> (jquery.jqGrid.src.js:8368)HTMLSelectElement.dispatch上的
(jquery.min.js:3)HTMLSelectElement.r.handle上的
(jquery.min.js:3)

推荐答案

在我看来,问题的主要原因是 cellEdit:true 一起使用内联编辑方法,例如 editRow inSelectRow 。 jqGrid支持三种主要的替代编辑模式:倾斜编辑,单元格编辑和表单编辑。如果启用关于 cellEdit:true 选项的单元格编辑,则将永远不会调用回调 onSelectRow 即可。单元格编辑通常意味着单元格选择,而不是行选择。因此,使用 cellEdit:true 可以防止通常调用 onSelectRow 回调。新选项 noCellSelection:true 是在免费的jqGrid 4.15.0中引入的,它将很快发布。它允许将行选择与单元格编辑相结合,但在 onSelectRow 内调用 editRow 即使在 cellEdit:true with noCellSelection:true ,因为它将取消刚刚开始的单元格编辑。

The main reason of your problem seems to me the option cellEdit : true together with inline editing methods like editRow inside of onSelectRow. jqGrid supports three main alternative editing modes: incline editing, cell editing and form editing. If you enable cell editing with respect of the option cell true then the callback onSelectRow will be never called. Cell editing means typically cell selection instead of row selection. Thus the usage of cell true prevent typically calling of onSelectRow callback. New option noCellSelection: true is introduced in free jqGrid 4.15.0, which will be soon released. It allows to combine row selection with cell editing, but calling of editRow inside of onSelectRow is not good even in case of cell true with noCellSelection: true, because it will cancel just started cell editing.

我的简短建议如下:您应该决定要使用哪种一个编辑模式。如果使用单元格编辑( cellEdit:true ),则应删除未使用的 onSelectRow serializeRowData 并添加 serializeCellData 或者 beforeSubmitCell 以扩展发布到服务器的数据。 serializeCellData 的代码可以是相同的,用于 serializeRowData 。或者,回调 beforeSubmitCell 可以返回对象 {test_value:postParams.test_value} {} 。从 beforeSubmitCell 返回的对象将与单元格编辑的标准参数组合(扩展)(请参阅)。

My short recommendation is following: you should decide, which one editing mode you want to use. In case of usage cell editing (cell true) you should remove unused onSelectRow and serializeRowData and to add serializeCellData or alternatively beforeSubmitCell to extend the data posted to the server. The code of serializeCellData could be the same, which you use for serializeRowData. Alternatively the callback beforeSubmitCell could return object {test_value: postParams.test_value} or {}. The object returned from beforeSubmitCell will be combined (extended) with the standard parameters of cell editing (see the old documentation).

这篇关于如何在使用内联编辑时在jqgrid中发布静态值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 23:03