jQuery JQGrid - OndblClickRow 事件以按所选行选择字段值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10807263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 09:47:31  来源:igfitidea点击:

JQGrid - OndblClickRow event to select field value by row selected

jqueryjqgrid

提问by nsilva

I'm really struggling with this and can't seem to get this to work.

我真的很挣扎,似乎无法让它发挥作用。

Basically I have a bookings table, e.g.

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

id    bookref    account    fare

1     BR1          101      10.00

2     BR2          202      20.00

My Jqgrid shows all this information, what I want to do is get the bookref value by which row is selected. The current function I have is:

我的 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);

    },

When I double click the first row I get 'BR1' returned which is correct, if I double click any other row I still get 'BR1' when I should get 'BR2' if the second row is clicked.

当我双击第一行时,我会返回“BR​​1”,这是正确的,如果我双击任何其他行,我仍然会得到“BR1”,而如果单击第二行,我应该得到“BR2”。

Can somebody please help me with this? Would massively appreciated it

有人可以帮我解决这个问题吗?会非常欣赏它

回答by vissu

If you see here in my code, I am also using ondblClickRowin my grid. If you see here, I am getting all row values and making my own changes what ever I want, and finally loading the job details page with document.location.href.
I am able to do this for all rows in the grid.

如果你在我的代码中看到这里,我也在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;
},

If you want see my full grid code:

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

$("#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}
    );

回答by richie-torres

No use selrow, but this is no the row of the event, with concurrency can fail

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

Check this:

检查这个:

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