我有一个包含2列的JQgrid ..我正在粘贴我在下面试过的代码..
var UserArr = new Array();
function Grid()
{
$("#users_grid").jqGrid({
colNames: ['Site_Name', 'Details'],
colModel: [{ name: 'Site_Name', index: 'Site_Name', width: 130,editable: false, sortable: false,formatter: 'showlink', formatoptions: { baseLinkUrl: 'url of respective site i have clicked'}},
{ name: 'Details', index: 'Details', width: 400, editable: false, sortable: false }],
width: 400,
height: 'auto',
multiselect: true
});
var postJSONData = JSON.stringify({ 'parentitem': parent,'childitem':child });
$.ajax({
type: 'POST',
data: postJSONData,
url: 'ManageAssetService.asmx/DisplayGridData',
dataType: 'json',
async: false,
contentType: 'application/json; charset=utf-8',
success: function success(response) {
UserArr = response.d;
},
error: function failure(response) {
alert(response.message);
alert('failed to fetch user details');
}
});
var mydata;
for (var i = 0; i <5; i++) {
mydata = {};
mydata.Url= UserArr[i].Url;
mydata.Details= UserArr[i].Details;
$("#users_grid").jqGrid('addRowData', 'GridData_Row_' + (i + 1), mydata);
}
}
我将在JQgrid中显示网站名称及其中的一些详细信息。现在,当我点击它时,Site_Name将是一个超链接,它应该重定向到相应的网址。我怎么能实现这个...我还要添加动态网格数据。那么我应该在哪里给出Site_Name列数据的相应URL以及如何将其链接到...
请帮助..
答案 0 :(得分:3)
我有这样的解决方案..
JQgrid列应该像这样定义:
colNames: ['Site_Name', 'Details'],
colModel: [{ name: 'Site_Name', index: 'Site_Name', width: 130,editable: false, sortable: false,formatter: 'showlink', formatoptions: { baseLinkUrl: 'javascript:', showAction: "Link('", addParam: "');"} },
{ name: 'Details', index: 'Details', width: 400, editable: false, sortable: false }],
Javascript功能:
function Link(id) {
var row = id.split("=");
var row_ID = row[1];
var sitename= $("#users_grid").getCell(row_ID, 'Site_Name');
var url = "http://"+sitename; // sitename will be like google.com or yahoo.com
window.open(url);
}
多数民众赞成......