最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin7PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far