0

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.

enb081
  • 3,831
  • 11
  • 43
  • 66
M Benmos
  • 99
  • 3
  • 12

2 Answers2

4
$('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.​

Farzher
  • 13,934
  • 21
  • 69
  • 100
  • what if I use... ondblClickRow: function(rowid){MORE CODE GOES HERE} – M Benmos Feb 21 '12 at 18:43
  • I don't know what jqgrid is, but this might help. http://stackoverflow.com/questions/2357126/how-to-access-the-fields-of-a-jqgrid-row – Farzher Feb 21 '12 at 18:57
  • Really good to have shown that plain javascript is perfect as well and as well readable – Robert Sep 19 '17 at 05:30
1

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);
Ani
  • 328
  • 1
  • 3
  • 17
  • Thanks that's what I was looking for. Actually the rowid is passed to the function when the doubleclick event occurs. So no need to find the selId (aka rowid). The rest of the your code worked!! – M Benmos Feb 22 '12 at 00:19
  • Here is the answer to my question thanks to Anoop's contribution: ondblClickRow: function(rowid) { var data = jQuery("#myGrid").jqGrid('getRowData',rowid); var MyCellContent = data.MyColumnName; MORE_CODE_HERE; } – M Benmos Feb 22 '12 at 00:29