简体   繁体   English

在鼠标悬停时从jqgrid获取数据

[英]Obtaining data from jqgrid on mouseover

I'm trying to do a mouseover for the jquery and when the mouse is hovered over a certain row I can get the id from that row and populate information and display an image. 我正在尝试对jquery进行鼠标悬停,当鼠标悬停在特定行上时,我可以从该行获取id并填充信息并显示图像。 However, I have been having the hardest time trying to do so. 但是,我一直很难做到这一点。

Here is what I want to happen 这是我想发生的事情

Just like in the onSelectRow where I obtain the data using the following code 就像在onSelectRow中,我使用以下代码获取数据一样

var ret = $('#list').jqGrid('getRowData', Id);

I want to use when I do a mouseover. 我要在鼠标悬停时使用。 However, I don't see a way of doing this. 但是,我看不到这样做的方法。 I tried the following under gridComplete 我在gridComplete下尝试了以下内容

gridComplete: function() {'.jqgrow').mouseover(function(e) {
 var rowId = $('.jqgrow').parent(tr:first).attr('id');
 alert("You rolled over " + rowId.Id);
});
}

but it only gave me the ide number of the row of that table inside the jqgrid and I need the data from that row instead. 但是它只给了我jqgrid中该表行的ide号,而我需要该行中的数据。

For instance, in my data I have Id, FirstName, LastName, FullName, Title, SortID 例如,在我的数据中,我具有Id,FirstName,LastName,FullName,Title,SortID

I would like to present a picture on the right side of my HTML page when hovered over certain rows by passing the Id to the HTML page, and querying through an array. 当将鼠标悬停在某些行上时,我想在HTML页面的右侧显示图片,方法是将Id传递给HTML页面,并通过数组进行查询。 If I can some how get the actual Id that's within my dataset I can do the rest. 如果我能找到如何获取数据集中的实际ID,我就可以做剩下的事情。

Any help would be lovely. 任何帮助将是可爱的。

I have given the entire code of my jqGrid at the bottom for reference. 我在底部给出了jqGrid的整个代码以供参考。

jQuery("#list").jqGrid({
url: '/Providers/DynamicGridData/',
datatype: 'json',
mtype: 'GET',
colNames: ['Id', 'LastName', 'FirstName', 'FullName', 'Title', 'Url', 'SortId'],
colModel: [
{ name: 'Id', index: 'Id', width: 30, align: 'left', hidden: true },
{ name: 'LastName', index: 'LastName', width: 30, align: 'left', hidden: true },
{ name: 'FirstName', index: 'FirstName', width: 30, align: 'left', hidden: true },
{ name: 'FullName', index: 'FullName', width: 100, align: 'left' },
/*{ name: 'FirstName', index: 'FirstName', width: 100, align: 'left' },*/
{name: 'Title', index: 'Title', width: 200, align: 'left' },
{ name: 'Url', index: 'Url', width: 30, align: 'left', hidden: true },
{ name: 'SortId', index: 'SortId', width: 30, align: 'left', hidden: true}],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
scrollOffset: 0,
width: '425',
altRows: 'true',
altClass: 'ui-priority-secondary',
autowidth: 'true',
height: '300',
altRows: 'true',
altClass: 'ui-priority-secondary',
viewrecords: true,
caption: 'Clinical Providers',
onSelectRow: function() {
var Id = $("#list").jqGrid('getGridParam', 'selrow');
if (Id) {
var ret = $('#list').jqGrid('getRowData', Id);
var url = ret.Url;
url.split(' ').join('');
//alert("id=" + ret.Id + "FullName=" + ret.FullName + "...");
window.location = "/" + url;
}
else { alert("Please select a row"); }
},
gridComplete: function() {
$('.jqgrow').mouseover(function(e) {
var rowId = $('.jqgrow').
alert("You rolled over " + rowId.Id);
});
}
});

I'm trying this code and it works fine: 我正在尝试此代码,它工作正常:

gridComplete: function() {
    $('.jqgrow').mouseover(function(e) {
        var rowId = $(this).attr('id');
        alert('You rolled over ' + rowId);
    });
}

I am confused - when you say: 我很困惑-当您说:

var rowId = $('.jqgrow').parent(tr:first).attr('id');

That should be returning the ID of the row. 那应该返回行的ID。 You can then pass rowID to the getRowData method to retrieve additional data for the row. 然后,您可以将rowID传递给getRowData方法,以检索该行的其他数据。

try this code..this code work... this code retrieve jqgrid row object .. 试试这个代码..这个代码的工作...这个代码检索jqgrid行对象..

$('.jqgrow').mouseover(function(e) {
 var rowId = $(this).attr('id');
 var dataFromTheRow = jQuery("#list").jqGrid('getRowData',rowId);// this is your jqgrid row object;
 alert('your jqgrid row object id = ' + dataFromTheRow.id);
               });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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