【问题标题】:JQGrid readonly and edit optionJQGrid 只读和编辑选项
【发布时间】:2012-11-09 10:55:16
【问题描述】:

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

{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");
        },

谢谢

【问题讨论】:

    标签: javascript jquery jqgrid


    【解决方案1】:

    如果我目前了解您的问题,您可以在beforeShowForm 回调中的编辑表单中为$("#product_image") 字段设置readonly 属性。请参阅the answerthis one 以获取相应的代码示例。

    更新:从您发布的代码中可以看出您使用单元格编辑 (cellEdit: true)。不支持cell editing 与jqGrid 的其他编辑模式(form editinginline editing)一起使用。

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

    如果您确实需要使用单元格编辑,您可以将“not-editable-cell”类添加到“product_image”列。您可以在colModel 中使用classes: "not-editable-cell",也可以根据需要动态生成(参见the answer 中的the demo)。该类将仅在单元格编辑中使用,而在表单编辑中将被忽略。

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

    对您的代码的最后一句话:您对 两个 列使用index:'ProductId' 似乎很奇怪:ProductIdproduct_image。是不是打字错误?

    【讨论】:

    • 我的问题是相反的,我希望普通网格列 b 只读,然后我可以编辑它的编辑面板。
    • @RoryStandley:我不明白你的意思。 “普通网格列”未处于编辑模式。所以你没有可以只读的字段。如果你实现了一些特殊的场景,比如自定义格式化程序或类似的东西,你需要描述它。如果您想使用both 编辑模式:内联编辑和表单编辑,您应该准确描述您激活编辑的方式。目前 jqGrid 提供了多种方式,具体实现方式取决于所选择的方式。
    • 当网格加载时,我可以将列 product_image 设为只读。这就是我需要发生的事情,用户可以读取数据但不能编辑。当用户选择一行数据并单击加载编辑对话框的“编辑”按钮时,我希望 product_image 在此对话框中可编辑,别无其他。
    • @RoryStandley:加载网格后网格的所有列都只包含文本(如果你不使用一些特殊的格式化程序,比如formatter: "checkbox", formatoptions: {disabled: false}),所以所有列都是只读。所以我真的不明白你在做什么。如果您将问题附加到创建 jqGrid 的 JavaScript 代码中可能会更好。
    • 我已经添加了我正在使用的代码。也许我没有为你正确解释它!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多