【问题标题】:Get column value of a JQgrid table when a row is selected选择行时获取JQgrid表的列值
【发布时间】:2012-08-23 08:35:16
【问题描述】:

当在 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});

任何人都可以帮我解决这个问题吗?

【问题讨论】:

    标签: javascript jquery html jqgrid


    【解决方案1】:

    您应该处理onSelectRow 事件(在单击该行后立即引发该事件),然后您可以使用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});
    

    这应该可以得到你想要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-03
      • 1970-01-01
      • 1970-01-01
      • 2022-11-24
      • 1970-01-01
      • 2011-02-04
      • 1970-01-01
      • 2012-01-06
      相关资源
      最近更新 更多