Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 选择行时获取JQgrid表的列值_Javascript_Jquery_Html_Jqgrid - Fatal编程技术网

Javascript 选择行时获取JQgrid表的列值

Javascript 选择行时获取JQgrid表的列值,javascript,jquery,html,jqgrid,Javascript,Jquery,Html,Jqgrid,当在jqgrid表中选择(单击)一行时,我想在javascript函数中获取2列的值。我想在每一行上添加一个javascript onclick事件,javascript函数获取所选行的col3和col4的值。我的代码是 jQuery("#table1").jqGrid({ url:'petstore.do?q=1&Path='+path, datatype: "json", colNames:['col1','col2','col3','

当在jqgrid表中选择(单击)一行时,我想在javascript函数中获取2列的值。我想在每一行上添加一个javascript onclick事件,javascript函数获取所选行的col3和col4的值。我的代码是

jQuery("#table1").jqGrid({
        url:'petstore.do?q=1&Path='+path,
        datatype: "json",
        colNames:['col1','col2','col3','col4'],
        colModel:[
                  {name:'col1',index:'col1',sortable:true,width:250},
              {name:'col2',index:'col2',sortable:true,width:100},
              {name:'col3',index:'col3', sortable:true,width:100},
              {name:'col4',index:'col4', sortable:true},
        ],
        multiselect: false,
        paging: true,
        rowNum:10,
        rowList:[10,20,30],
        pager: $("#pager")

    }).navGrid('#pager',{edit:false,add:false,del:false});

有人能帮我解决这个问题吗?

您应该处理
onsetrow
事件(该事件在单击行后立即引发),然后您可以使用
getRowData
方法以将所选行数据获取为数组:

$('#table1').jqGrid({
    url: 'petstore.do?q=1&Path='+path,
    datatype: 'json',
    colNames: ['col1', 'col2', 'col3', 'col4'],
    colModel: [
               {name:'col1', index:'col1', sortable:true, width:250},
               {name:'col2', index:'col2', sortable:true, width:100},
               {name:'col3', index:'col3', sortable:true, width:100},
               {name:'col4', index:'col4', sortable:true}
    ],
    multiselect: false,
    paging: true,
    rowNum: 10,
    rowList: [10,20,30],
    pager: $('#pager'),
    onSelectRow: function(rowId){ 
        var rowData = $('#table1').jqGrid('getRowData', rowId);
        //You can access the desired columns like this --> rowData['col3']
        ...
    }
}).navGrid('#pager', {edit:false, add:false, del:false});
这会让你得到你想要的