javascript 如何在 jqGrid 中检索选定的单元格值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6065299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 19:20:38  来源:igfitidea点击:

How do you retrieve selected cell value in jqGrid?

javascriptjqueryjqgrid

提问by ngen

With the code below, it displays the cell value that was last selected. How do I display the cell value of the row I just clicked on?

使用下面的代码,它显示上次选择的单元格值。如何显示我刚刚单击的行的单元格值?

jQuery('#grid').click( function() {
  var grid = jQuery('#grid);
  var sel_id = grid.jqGrid('getGridParam', 'selrow');
  var myCellData = grid.jqGrid('getCell', sel_id, 'source_id');
  $('#selrow').html("Source ID selected:" + myCellData);
});

回答by Oleg

You code is a little strange because you use jQuery binding to clickinstead of the usage of events like onCellSelect. If you use this you should use the first parameter of the click function, for example e(jQuery('#grid').click(function(e) {...});). The e.targetis the DOM element of the cell (<td>) or an element inside of cell (like <a>inside of <td>) which the user clicked. The code $(e.target).closest("td")will gives you the cell.

您的代码有点奇怪,因为您使用 jQuery 绑定来click代替onCellSelect等事件的使用。如果您使用它,您应该使用点击函数的第一个参数,例如e( jQuery('#grid').click(function(e) {...});)。的e.target是细胞(的DOM元素<td>)或电池的内部元件(如<a>内部<td>其中用户点击)。该代码$(e.target).closest("td")将为您提供单元格。

If you do decide to use onCellSelectI would recommend you to read the answerwith the demo.

如果你决定使用onCellSelect我建议你阅读的答案演示

回答by actionshrimp

When setting up the grid, you can define a callback function for the onCellSelect event.

在设置网格时,您可以为 onCellSelect 事件定义一个回调函数。

e.g:

例如:

var grid = jQuery('#grid').jqGrid( {
 ... default grid setup ...,
 onCellSelect: function(rowid, icol, cellcontent, e) { alert(cellcontent); },
 });

A list of all the jqGrid events is here: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events

所有 jqGrid 事件的列表在这里:http: //www.trirand.com/jqgridwiki/doku.php?id=wiki:events