简体   繁体   中英

jqGrid HOWTO: Get the value of specific cell upon double click on row

I'd like to be able to double click on any part of a given row and open a new html page (based on specific cell value/content). Basically I have all NY counties, each in one row:

County - City - State

Manhatan - New York - NY 

Brooklyn - New York - NY

Bronx - New York - NY

Westchester - New York - NY

etc.

I need to be able to get the cell value in the County column and use it to run a function. Example: if I double click on the first row, that should open a new html page about Manhattan. I tried some answers that were posted for a kind of similar question (about editing) but they didn't work.

$('table').on('dblclick', 'tr', function() {
    var rowCountry = $(this).find('td:first').text();
});

This says when you double click on any row in your table, find the first cell of that row, and store its text value in a variable.​

Ondoubleclick of a row in grid call a function.

Use the below lone of code to get the selected row id (primary key of row) and then get the row contents using that id and then get the column content using the column name. Once you have the country name, open whatever page you want based on country.

selId = jQuery("#myGrid").jqGrid('getGridParam','selarrrow');
alert("Selected Id is ->"+selId);
var data = jQuery("#myGrid").jqGrid('getRowData',selId);
alert("Status ->"+data.country);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM