【发布时间】:2011-09-04 21:16:28
【问题描述】:
您好,我正在尝试通过关注 trirand 的 this document 来使 showlink 格式化程序正常工作。
我想要实现的是一个超链接,我可以点击一个编辑视图来更新/编辑记录。但由于某种原因,我想在其中显示超链接的列是空的。
这是我的代码sn-ps,链接是最后一列:
<script type="text/javascript">
$(document).ready(function () {
$("#grid_products").jqGrid({
jsonReader: {
repeatitems: false,
id: 'Guid'
},
url: '/Product/jqgridJSON/',
datatype: 'json',
mtype: 'GET',
colNames: ['ProductCode', 'ProductDescription', 'DefaultSellPrice', 'LastCost', 'Edit'],
colModel: [
{ name: 'ProductCode', index: 'Productcode' },
{ name: 'ProductDescription', index: 'ProductDescription' },
{ name: 'DefaultSellPrice', formatter: 'currency', index: 'DefaultSellPrice' },
{ name: 'LastCost', formatter: 'currency', index: 'LastCost' },
{ name: 'MyLink',
edittype: 'select',
formatter: 'showlink',
formatoptions: { baseLinkUrl: '/Product/Update/', idName: 'Guid' }
},
],
pager: '#pager',
rowNum: 10,
rowList: [20, 50, 100, 200],
sortname: 'ProductCode',
sortorder: 'asc',
viewrecords: true,
width: 'auto',
height: 'auto',
caption: 'Products'
}).navGrid('#pager', { edit: true, add: false, del: false });
});
</script>
@{
ViewBag.Title = "JSONGrid";
}
<h2>JSONGrid</h2>
<table id="grid_products"></table>
<div id="pager"></div>
jqGrid 的格式化程序适用于货币,但由于某种原因,它没有显示为超链接。
更新:
使用自定义格式化程序让它工作。
...
{ name: 'MyLink',
formatter: myLinkFormatter,
},
...
function myLinkFormatter (cellvalue, options, rowObjcet) {
return '<a href = "/Product/Edit/' + options.rowId + '">Edit this product</a>';
}
【问题讨论】:
标签: javascript jquery jqgrid