javascript - Get column value of a JQgrid table when a row is selected - Stack Overflow

I want to get values of 2 column in a javascript function when a row is selected(clicked) in jqgrid tab

I want to get values of 2 column in a javascript function when a row is selected(clicked) in jqgrid table.what i want is add a javascript onclick event on each row and javascript function gets the values of col3 and col4 of selected row.my code is

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

can any body help me out from this ?

I want to get values of 2 column in a javascript function when a row is selected(clicked) in jqgrid table.what i want is add a javascript onclick event on each row and javascript function gets the values of col3 and col4 of selected row.my code is

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

can any body help me out from this ?

Share Improve this question asked Aug 23, 2012 at 8:35 Ashish PaneryAshish Panery 1,2263 gold badges14 silver badges24 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You should handle the onSelectRow event (which is raised immediately after the row has been clicked) and then you can use getRowData method in order to get selected row data as an array:

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

This should get you what you want.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745644943a4637913.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信