JQGrid - OndblClickRow事件选择按行选择的字段值

时间:2012-05-29 21:57:02

标签: jquery jqgrid

我真的在努力解决这个问题,似乎无法让它发挥作用。

基本上我有一张预订表,例如

id    bookref    account    fare

1     BR1          101      10.00

2     BR2          202      20.00

我的Jqgrid显示了所有这些信息,我想要做的是获取选择哪一行的bookref值。我目前的职能是:

    ondblClickRow: function(rowid)
    {
        var grid = $('#bookings');
        var sel_id = grid.jqGrid('getGridParam', 'selrow');
        var myCellData = grid.jqGrid('getCell', sel_id, 'bookref');

        alert(myCellData);

    },

当我双击第一行时,我得到'BR1',这是正确的,如果我双击任何其他行我仍然得到'BR1',如果第二行被点击我应该得到'BR2'。

有人可以帮帮我吗?会非常感激它

2 个答案:

答案 0 :(得分:4)

如果你在我的代码中看到这里,我也在我的网格中使用ondblClickRow。如果您在此处看到,我将获取所有行值并根据需要进行自己的更改,最后使用document.location.href加载作业详细信息页面。
我能够为网格中的所有行执行此操作。

ondblClickRow: function(rowId) {
    var rowData = jQuery(this).getRowData(rowId); 
    var jobNumber = rowData['jobNumber'];
    var jobName = rowData['description'];
    var jobCustomer = rowData['customerName'];
    var jobStatus = rowData['jobStatus'];
    jobName = jobName.replace(/&/g, "``");
    jobName = jobName.replace(/#/, "__");
    var aQryStr = "jobNumber=" + jobNumber + "&jobName=" + jobName + "&jobCustomer=" + jobCustomer;
    console.log("./jobflow?token=view&" + aQryStr);
    document.location.href = "./jobflow?token=view&" + aQryStr;
},

如果你想查看我的完整网格代码:

$("#jobsGrid").jqGrid({
        url:'../job_controller',
        datatype: 'JSON',
        mtype: 'POST',
        pager: jQuery('#jobsGridPager'),
        colNames:['Job #','Project','City', 'Rep', 'Status', 'Customer', 'Cust PO #', 'Rep. #'],
        colModel :[
            {name:'jobNumber', index:'jobNumber', align:'left', width:50, editable:true,hidden:false, edittype:'text',
                    editoptions:{size:30,readonly:true},editrules:{edithidden:false,required:false}},
            {name:'description', index:'description', align:'left', width:150,hidden:false, editable:true, 
                    editoptions:{size:20,readonly:false, alignText:'right'},editrules:{edithidden:true,required:true}},
            {name:'locationCity', index:'locationCity', align:'', width:90,hidden:false, editable:true,
                    editoptions:{size:20,readonly:false, alignText:'right'},editrules:{edithidden:true,required:true}},
            {name:'initials', index:'initials', align:'center', width:30,hidden:false, editable:true,
                    editoptions:{size:20,readonly:false, alignText:'right'},editrules:{edithidden:true,required:true}},
            {name:'jobStatus', index:'jobStatus', align:'center', width:60,hidden:false, editable:true,
                    editoptions:{size:20,readonly:false, alignText:'right'},editrules:{edithidden:true,required:true}},
            {name:'customerName', index:'customerName', align:'', width:150,hidden:false, editable:true, 
                    editoptions:{size:20,readonly:false, alignText:'right'},editrules:{edithidden:true,required:true}},
            {name:'customerPONumber', index:'customerPONumber', align:'center', width:90, hidden:false, editable:true, 
                    editoptions:{}, editrules:{edithidden:true,required:false}},
            {name:'code', index:'code', align:'center', width:40,hidden:false, editable:true,
                    editoptions:{size:20,readonly:false, alignText:'right'},editrules:{edithidden:true,required:true}}
        ],
        rowNum: 50, pgbuttons: true,    
        recordtext: '',
        rowList: [50, 100, 200, 500, 1000],
        viewrecords: true,
        pager: '#jobsGridPager',
        sortname: 'employeeId', sortorder: "asc", imgpath: 'themes/basic/images',   caption: 'Jobs',
        height:547, width: 1140,/*scrollOffset:0,*/ rownumbers:true, altRows: true, altclass:'myAltRowClass', rownumWidth: 45,
        ondblClickRow: function(rowId) {
            var rowData = jQuery(this).getRowData(rowId); 
            var jobNumber = rowData['jobNumber'];
            var jobName = "" + rowData['description'];
            var jobCustomer = rowData['customerName'];
            var jobStatus = rowData['jobStatus'];
            jobName = jobName.replace(/&/g, "``");
            jobName = jobName.replace(/#/, "__");
            var aQryStr = "jobNumber=" + jobNumber + "&jobName=" + jobName + "&jobCustomer=" + jobCustomer;
            console.log("./jobflow?token=view&" + aQryStr);
            document.location.href = "./jobflow?token=view&" + aQryStr;
        },
        jsonReader : {
            root: "rows",
            page: "page",
            total: "total",
            records: "records",
            repeatitems: false,
            cell: "cell",
            id: "id",
            userdata: "userdata"
        }
    }).navGrid('#jobsGridPager', add:false,edit:false,del:false,refresh:false,search:false}
    );

答案 1 :(得分:1)

没有使用selrow,但这不是事件的行,并发可能会失败

检查一下:

ondblClickRow: function(rowid)
{   
    var grid = $('#bookings');    
    var myCellData = grid.jqGrid('getCell', rowid, 'bookref');
    alert(myCellData);
}