禁用内联和单元格编辑,只允许在jqgrid中进行表单编辑

时间:2011-02-02 16:39:47

标签: jqgrid

我有一个网格,它维护某个实体(例如文档)的元数据的映射。在这种情况下,我们只需添加或编辑。编辑只是为了使记录失效

由于这种情况,我们没有必要使用单元格或内联编辑。表单编辑选项将是最好的

但是,这些表单只显示那些具有“editable:true”

的列

那么,如何在网格中禁用编辑并仅为表单启用它?

onSelectRow根本不会发射。我错过了什么吗???我正在使用jqgrid 3.8

这就是我的尝试:

var metaGrid = jQuery("#" + nodeMetaDataGrid);
        metaGrid.jqGrid({
            pager: jQuery("#" + nodeMetaDataGridPager),
            emptyrecords: "No records to view",
            sortname: 'Id',
            rowNum: 30,
            rowList: [50, 100, 'ALL'],
            sortorder: "asc",
            height: "auto",
            autowidth: true,
            colNames: ['Id', 'Meta Data Type', 'Meta Data Value', 'Status', 'Date Added', 'Date Removed'],
            colModel: [
              { name: 'Id', index: 'Id', hidden: true, key: true },
              { name: 'MetaType', index: 'MetaType', width: 30, editable: false, edittype: "select", editoptions: { dataUrl: "My/GetList"} },
              { name: 'MetaValue', index: 'MetaValue', width: 30, editable: false, editrules: { required: true} },
              { name: 'Status', index: 'Status', width: 10, editable: false, edittype: "select", editoptions: { value: "A:Active;I:Inactive"} },
              { name: 'DateAdded', index: 'DateAdded', width: 20, editable: false },
              { name: 'DateRemoved', index: 'DateRemoved', width: 20, editable: false }
              ],
            datatype: 'json',
            viewrecords: true,
            mtype: 'GET',
            jsonReader: {
                root: "rows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems: false,
                userdata: "userdata"
            },
            url: getUrl,
            multiselect: false,
            //editurl: "someurl"
            caption: "Available Meta Data",
            onSelectRow: function (id) {
                alert("Before Iff statement");
                if (id && id !== lastSel) {
                    alert("hi, selected");
                    jQuery(this).restoreRow(lastSel);
                    var cm = metaGrid.jqGrid('getColProp', 'MetaType');
                    cm.editable = false;
                    //grid.jqGrid('addRow', id, true, null, null, 'someURL');
                    //cm.editable = true;
                    lastSel = id;
                }
            }
        })
        .navGrid("#" + nodeMetaDataGridPager, { view: false, del: false, add: true, edit: true, search: false },
           {
               //Edit mode
               height: 150,
               reloadAfterSubmit: true,
               modal: true,
               closeOnEscape: true,
               url: "someURL"                   
           },
           {   //Add mode
               height: "auto",
               reloadAfterSubmit: false,
               modal: true,
               closeOnEscape: true,
               url: "someURL",                   
               recreateForm: true,
               //trying to use this because onSelectRow does not fire
               beforeShowForm: function (form) {                       
                   var cm = metaGrid.jqGrid('getColProp', 'MetaType');                       
                   cm.editable = true;
               }
           },
           {     
                //Delete mode                  
           },
           {
           //View mode               
           }
         ); 

谢谢, Apploader

2 个答案:

答案 0 :(得分:1)

也许您可以删除此声明:

onSelectRow: function (id) {
                alert("Before Iff statement");
                if (id && id !== lastSel) {
                    alert("hi, selected");
                    jQuery(this).restoreRow(lastSel);
                    var cm = metaGrid.jqGrid('getColProp', 'MetaType');
                    cm.editable = false;
                    //grid.jqGrid('addRow', id, true, null, null, 'someURL');
                    //cm.editable = true;
                    lastSel = id;
                }

并添加“cellEdit:false”

答案 1 :(得分:0)

正如kayla所说,删除你的onSelectRow块并使用cellEdit ... http://www.trirand.com/jqgridwiki/doku.php?id=wiki:cell_editing