4

我在 MVC3 中使用 JQuery 创建了一个网格,该网格显示来自模型的数据,但现在我打算放置一个超链接到网格中的一列,这样当用户点击他应该能够查找的链接时与行值有关的数据..下面是显示我的网格的代码。

<script type="text/javascript">
$(document).ready((function () {
    $("#list").jqGrid({
        url: '/list/GetDet/', 
        datatype: 'json',
        mtype: 'GET',
        colNames: ['Code', 'Name', 'Location'], //column name
        colModel: [
      { name: 'Code', index: 'Code', width: 100, align: 'right' },
      { name: 'Name', index: 'Name', width: 100, align: 'left' },
      { name: 'location', index: 'location', width: 100, align: 'left'}],

        pager: $('#pager'),
        rowNum: 5,
        rowList: [5, 10, 20, 50],            
        sortname: 'Code',
        sortorder: "desc",
        viewrecords: true,
        caption: 'Details'            
    });
})); 
</script> 

如果我打算创建指向名称列的链接,我该如何提供

4

4 回答 4

0

我认为您在发送 URL 时遇到问题。
这是解决该问题的链接。

于 2012-09-05T11:24:54.497 回答
0

您可以使用该getCell方法(如 jqGrid 文档中所述)。一旦你在你的 javascript 中有这个值,你可以用任何你喜欢的方式处理它。

于 2012-09-05T15:19:51.567 回答
0

在您放置实际链接或要链接的 ID 的 getData 操作中,在您创建单元格的位置使用完整的 html 字符串。服务器可以发送<a href="/controller/action/id">View</a>给客户端,它会显示为一个链接。这不会影响任何搜索或排序,因为它们是在实际索引而不是超链接上完成的。

我通常会在服务器端准备我的操作,但如果您想在客户端执行此操作,您可以使用指定自定义函数作为格式化程序并以您想要的任何方式格式化值。 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options 看看格式化程序选项

于 2012-11-09T01:44:27.777 回答
0

对列使用驼峰nameindexdon't use capital letter在声明列的起始字时。如果使用网格不加载。

例子:

{ name: 'code', index: 'code', width: 100, align: 'right' }, { name: 'name', index: 'name', width: 100, align: 'left' }, { name: 'location', index: 'location', width: 100, align: 'left'}],

您的问题与之前提出的问题有关Retrieve value of cells, when in edit mode in JqGridHow to return row values using hyperlink in jqgrid

editLink函数中使用列索引名称来获取行值。

function editLink(cellValue, options, rowdata, action)
{
    alert('Name: '+ rowdata.name);//alerts row value of column
    //return "<a href='/Admin/editProvider/" + rowdata.providerId + "' class='ui-icon ui-icon-pencil' ></a>";
}
于 2014-02-25T06:41:19.647 回答