高亮显示双击的单元格值以进行复制 [英] Highlight cell value on doubleclick for copy
问题描述
我有一个jqGrid.我想突出显示一行中的特定单元格ondbClickRow.这将使将单元格的值复制到剪贴板的任务变得容易.有人可以指导我如何执行此操作吗?谢谢!
I have a jqGrid. I would like to highlight a particular cell from a row, ondbClickRow. This would make the task of copying the value of a cell onto clipboard, easy for users. Can someone guide me on how to do this? Thanks!
推荐答案
通常可以,但是您应该关闭行选择以立即看到突出显示.因此,代码将与以下内容有关:
In general it would be possible, but you should probably switch off row selection to see highlighting immediately. So the code will be about the following:
beforeSelectRow: function () {
return false;
},
ondblClickRow: function (rowid, iRow, iCol, e) {
$(e.target).toggleClass('ui-state-highlight');
}
结果,您可以像这样的网格
As the result you can have the grid like
请参见相应的演示此处
UPDATED: If you need select the text in the grid cell you can use the idea described here. In case of usage inside of jqGrid the code could be the following:
var selectText = function (element) {
var doc = element.ownerDocument, selection, range;
if (doc.body.createTextRange) { // ms
range = doc.body.createTextRange();
range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
selection = window.getSelection();
if (selection.setBaseAndExtent) { // webkit
selection.setBaseAndExtent(element, 0, element, 1);
} else { // moz, opera
range = doc.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
}
};
$("#list").jqGrid({
// ... jqGrid options
ondblClickRow: function (rowid, iRow, iCol, e) {
selectText(e.target);
}
});
下一个演示演示了这一点:
这篇关于高亮显示双击的单元格值以进行复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!