【问题标题】:jqGrid. Disabling Multiselect on Edit modejq网格。在编辑模式下禁用多选
【发布时间】:2011-10-06 17:42:53
【问题描述】:

我正在使用这些字段和功能创建一个新的 jqgrid:

Deployment id','Branch', 'Release Name','Client id','# of hosts','Comments','Actions

-我在 TRUE 上有多选选项。

-我在每一行都有编辑/删除操作

-我的导航栏位于底部,带有添加/搜索选项。

我的行动是: 当我添加一条新记录时,我可以添加 BRANCH 字段和仅评论(这有效) 当我编辑一条记录时,我只能修改 COMMENT(也可以)

我的问题是关于 MULTISELECT 选项...

如果我点击 EDIT 按钮并且 MULTISELECT 取消选中一切正常.. 意味着只允许修改 COMMENT。

但是

如果在 Multiselect 列中选择了行,则 BRANCH 字段变为可编辑。

此外,我想在编辑某一行时阻止其他操作(意味着无法选中/取消选中编辑/删除另一行)

有人可以帮我做吗?

谢谢

ps:我尝试使用在这里找到的不同代码/示例,但没有成功。为了避免更多的混乱,我暂时不发布它。

    var lastSel;
    $(function(){ 

 $("#list").jqGrid({

  data: mydata, 
  datatype: "local", 

  colNames:['Deployment id','Branch', 'Release Name','Client id','# of hosts','Comments','Actions'],
  colModel:[ 
      {name:'deployment_id',index:'deployment_id',align:"right", sorttype:"int", width:120},    
      {name:'branch',index:'branch',align:"center", formatter:branchColor,editable: true,edittype:"select",editrules:{required:true},editoptions:{value:"option 1:option1;option2:option2"}},           
      {name:'release_name',index:'release_name',align:"center"},    
      {name:'client_id',index:'client_id',align:"right", sorttype:"int", width:60}, 
      {name:'num_hosts',index:'num_hosts',align:"right", sorttype:"int", width:60},
      {name:'comments',index:'comments',align:"center", editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"20"}},
      {name:'myac', width:80, fixed:true, sortable:false, resize:false, formatter:'actions',formatoptions:{keys:true}}  
  ],

         rowList : [20,30,50], 

         pager: '#pager', 
         sortname: 'deployment_id', 
         viewrecords: true,
         recordpos: 'right',      
         sortorder: "asc",
         sortable: true, 
       multiselect: true,
       shrinkToFit :true,
       viewrecords: true,


     onSelectRow: function(id){
        //alert("id:"+id);
        if (id == null) {
                         id = 0;
                                        if(id && id!==lastSel){

                                            //$('#list').jqGrid('restoreRow',lastSel);
                                            //$('#list').jqGrid('editRow',id,false);


                                            $("#jqg_list_" + id).attr("disabled","disabled");   
                                            lastSel=id;

                                        }
                    }
                    else {


                                var grId = $("#list").jqGrid('getGridParam','selrow');


    if(grId){
            $("#" + grId + "_branch").attr("disabled","disabled");
            $("#" + grId + "_branch").removeClass("editable");  
        }                                   

                    }                   
            },



}); 


// to modify The tool bar on bottom
$("#list").jqGrid('navGrid','#pager',{edit:false, edittitle: 'Modify a Deployment', 
                                         add:true, addtitle: 'Add a new Deployment',
                                         del:true, deltitle: 'Delete a Deployment',
                                         nav:{ addCaption: 'Columns'}
                                       },
{// edit option
 beforeShowForm: function(form) { 
                                   $('#branch', form).attr("disabled","disabled"); 

                                  },

//seems to be is not qworking   
 beforeSelectRow: function(rowid, e) { return false; },                               
 },

{// add option
 beforeShowForm: function(form) { 

                                    $('#branch option[value=""]', form).text('Select a branch')
                                    $('#branch option[value=""]', form).attr("selected", "selected");
                                    $('#branch', form).attr("disabled","");  



        var ids; 

    ids = $("#list").getGridParam('selarrrow'); 
    if(ids){        
                alert('array: ['+ids+']'); 
                alert('id in array[0]: '+ids[0]);
        }


                                   },
 addCaption: "Add a Deploymet"

},



{// delette option

},
{// Search option
    multipleSearch:true
},
{// view option

}   
);

【问题讨论】:

    标签: jqgrid


    【解决方案1】:

    最后我得到了很多测试的答案..我想分享一下..可能对其他人有用。 基本上我删除了 OnSelectRow 函数并修改了格式选项:{}添加标签 onEdit

    我在此链接中添加运行的示例/DEMO:DEMO ONLINE

    var mydata = [
    
        {
        "branch": "PACS-3-3-1",
        "comments": "migrated deployment",
        "client_id": 27,
        "deployment_id": 249,
        "release_name": null,
        "num_hosts": 12},
    
    {
        "branch": "PACS-3-1-1",
        "comments": "migrated deployment",
        "client_id": 27,
        "deployment_id": 144,
        "release_name": null,
        "num_hosts": 9},
    
    {
        "branch": "PACS-2-4-1",
        "comments": "2.6.1",
        "client_id": 27,
        "deployment_id": 78,
        "release_name": null,
        "num_hosts": 0},
    {
        "branch": "PACS-2-4-2",
        "comments": "PACS-2-4-2",
        "client_id": 27,
        "deployment_id": 46,
        "release_name": null,
        "num_hosts": 0}
    
    ];
    
    var lastSel;
    
    
    $("#list").jqGrid({
    
        data: mydata,
        datatype: "local",
    
        colNames: ['Deployment id', 'Branch', 'Release Name', 'Client id', '# of hosts', 'Comments', 'Actions'],
        colModel: [
            {
            name: 'deployment_id',
            index: 'deployment_id',
            align: "right",
            sorttype: "int",
            width: 120},
        {
            name: 'branch',
            index: 'branch',
            align: "center",
            editable: true,
            edittype: "select",
            editrules: {
                required: true
            },
            editoptions: {
                value: "option 1:option1;option2:option2"
            }},
        {
            name: 'release_name',
            index: 'release_name',
            align: "center"},
        {
            name: 'client_id',
            index: 'client_id',
            align: "right",
            sorttype: "int",
            width: 60},
        {
            name: 'num_hosts',
            index: 'num_hosts',
            align: "right",
            sorttype: "int",
            width: 60},
        {
            name: 'comments',
            index: 'comments',
            align: "center",
            editable: true,
            edittype: "textarea",
            editoptions: {
                rows: "2",
                cols: "20"
            }},
        {
            name: 'myac',
            width: 80,
            fixed: true,
            sortable: false,
            resize: false,
            formatter: 'actions',
            formatoptions: {
                keys: true,
                //hace que se abra el popup, en lugar de inlineedit
                //editformbutton: true,
                onEdit: function(rowid) {
                    //alert("in onEdit: rowid=" + rowid + "\nWe don't need return anything");
                    $("#" + rowid + "_branch").attr("disabled", "disabled");
                    $("#" + rowid + "_branch").removeClass("editable");
                }
            }}
        ],
    
        rowList: [20, 30, 50],
    
        pager: '#pager',
        sortname: 'deployment_id',
        viewrecords: true,
        recordpos: 'right',
        sortorder: "asc",
        sortable: true,
        multiselect: true,
        shrinkToFit: true,
    
    
    
    //    onSelectRow: function(id) {
            //alert("id:"+id);
           // if (id === null) {
           //     id = 0;
    //            if (id && id !== lastSel) {
    
                    //$('#list').jqGrid('restoreRow',lastSel);
                    //$('#list').jqGrid('editRow',id,false);
    
    //                $("#jqg_list_" + id).attr("disabled", "disabled");
    //                lastSel = id;
    
    //            }
    //        }
    //        else {
    
    
    //            var grId = $("#list").jqGrid('getGridParam', 'selrow');
    
    
    //            if (grId) {
    //                $("#" + grId + "_branch").attr("disabled", "disabled");
    //                $("#" + grId + "_branch").removeClass("editable");
    //            }
    
            //}
       // }
    
    
    
    });
    
    
    // to modify The tool bar on bottom
    $("#list").jqGrid('navGrid', '#pager', {
        edit: false,
        edittitle: 'Modify a Deployment',
        add: true,
        addtitle: 'Add a new Deployment',
        del: true,
        deltitle: 'Delete a Deployment',
        nav: {
            addCaption: 'Columns'
        }
    }, { // edit option
       // beforeShowForm: function(form) {
       //     $('#branch', form).attr("disabled", "disabled");
    
       // },
    
        //seems to be is not qworking   
        beforeSelectRow: function(rowid, e) {
            return false;
        }
    },
    
    { // add option
        beforeShowForm: function(form) {
    
    
            $('#branch', form).prepend("<option value=''>Select a branch</option>")
            //$('#branch option[value=""]', form).text('Select a branch');
            $('#branch option[value=""]', form).attr("selected", "selected");
            //$('#branch', form).attr("disabled", "");
    
    
    
            var ids;
    
            ids = $("#list").getGridParam('selarrrow');
            if (ids) {
                //alert('array: [' + ids + ']');
                //alert('id in array[0]: ' + ids[0]);
            }
    
    
        },
        addCaption: "Add a Deploymet"
    
    },
    
    
    
    { // delette option
    }, { // Search option
        multipleSearch: true
    }, { // view option
    });
    

    【讨论】:

      猜你喜欢
      • 2014-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多