0

谁能告诉我如何使一个特定列的内联编辑为假,但是当您编辑特定行时,该列是可编辑的,例如 -

{name:'product_image', index:'ProductId', width:25, align:'right', editable:true, edittype:'file'},

这完美地工作,我可以通过选择行并单击编辑按钮来编辑它<然后我将看到编辑对话框,然后我可以更改所述列的值。我想让网格视图中的列只读但是,我发现了以下内容 -

{name:'product_image', index:'ProductId', width:25, align:'right', editable:false, edittype:'file',editoptions:{readonly: false}},

但是,这只会使该列只读,并且在编辑模式下我无法更改该值。

$("#list").jqGrid({
    url:'products.php?storeId=<?php echo $_SESSION["valid_store"]; ?>',
    datatype: 'xml',
    mtype: 'GET',
    colNames:['Product Id','Product Description','Department','Category','Price','Sale Price','Quantity','Extended Description','Web Item','Image'],
    colModel :[ 
      {name:'ProductId', index:'ProductId', width:20}, 
      {name:'product_name', index:'product_name', width:50, editable:true, edittype:'text', search:true, stype:'text'},
      {name:'DepartmentName', index:'DepartmentName', width:40,sortable: false, editable: true, edittype: "select"},
      {name:'CategoryName', index:'CategoryName', width:40,sortable:false, editable:true, edittype:'select'}, 
      {name:'price', index:'price', width:15, align:'right', editable:true, edittype:'text'}, 
      {name:'sale_price', index:'sale_price', width:15, align:'right', editable:true, edittype:'text'}, 
      {name:'product_qty', index:'product_qty', width:10, align:'right', editable:<?php if($edit_qty == 1){echo "true";}else{echo "false";} ?>, edittype:'text'}, 
      {name:'product_description', index:'product_description', width:100, sortable:false, editable:true, edittype:'text'},
      {name:'web_item', index:'web_item', width:15,sortable:false, editable:true, edittype:'select',editoptions:{value:{1:'True',0:'False'}}}, 
      {name:'product_image', index:'ProductId', width:25, align:'right', edittype:'file', editable: false},
    ],
    loadComplete:function(){
        $("#list").setColProp('DepartmentName', { editoptions: { value: departments} });
        $("#list").setColProp('CategoryName', { editoptions: { value: categories} });
    },
    pager: '#pager',
    rowNum:40,
    rowList:[10,20,30,40,50,60,70,80,90,100],
    sortname: 'ProductId',
    sortorder: 'desc',
    viewrecords: true,
    gridview: true,
    caption: 'Products',
    autowidth: true,
    height: tableHeight,
    cellEdit: true,
    loadtext: 'Loading Products...',
    cellurl: 'edit_product.php?storeId=<?php echo $_SESSION["valid_store"]; ?>',
    editurl: 'edit_product.php?storeId=<?php echo $_SESSION["valid_store"]; ?>',
  }).navGrid('#pager',
    {
        del: false,
        add: <?php if($add_products == 1){echo "true";}else{echo "false";}?>,
        edit: true,
        search: true
    },
    {jqModal:true,closeAfterEdit: false,recreateForm:true,onInitializeForm : function(formid){
        $(formid).attr('method','POST');
        $(formid).attr('action','');
        $(formid).attr('enctype','multipart/form-data');
        },
        beforeShowForm:function(form){
            $("#product_image", form).attr("disabled", "false");
        },

谢谢

4

1 回答 1

1

如果我目前了解您的问题,您可以在回调内的编辑表单中设置字段readonly属性。有关相应的代码示例,请参见答案此答案。$("#product_image")beforeShowForm

更新:从您发布的代码中可以看到您使用单元格编辑cellEdit: true)。不支持将单元格编辑与jqGrid 的其他编辑模式(表单编辑内联编辑)一起使用。

可能cellEdit: true是偶然使用的?在这种情况下,您应该删除解决问题的选项。

如果您确实需要使用单元格编辑,您可以将 'not-editable-cell' 类添加到 'product_image' 列。您可以classes: "not-editable-cell"colModel中使用,也可以根据需要动态制作(请参阅答案的演示)。该类将仅用于单元格编辑,将被表单编辑忽略。

如果您确实需要同时使用单元格编辑和表单编辑,则必须在开始表单编辑之前restoreCell调用or saveCell(参见文档) (例如在beforeInitData中)。方法的所有参数都可以保存在最后调用的beforeEditCell回调中。

index:'ProductId'您的代码的最后一句话:您使用列似乎很奇怪:ProductIdproduct_image. 可能是打字错误吗?

于 2012-11-09T11:05:32.263 回答