您的位置:首页 > 其它

datagrid动态数据添加超链接的方法

2016-04-01 11:22 447 查看
首先,我我们要有一个json格式的datagrid_data.json文件,如下:



其次,在body下有个数据表格,引入json

<table class="easyui-datagrid" style="width:400px;height:250px" data-options="url:'datagrid_data.json',fitColumns:true,singleSelect:true">
<thead>
<tr>
<th data-options="field:'code',width:100">Code</th>
<th data-options="field:'name',width:100,formatter:planUrl">Name</th>
<th data-options="field:'price',width:100,align:'center'">Price</th>
<th data-options="field:'test',width:100">Test</th>
</tr>
</thead>
</table>

然后,在脚本script中,写超链接的方法(跳转的路径,想做的事情)

<link rel="stylesheet" type="text/css" href="../../js/jquery-easyui-1.4.3/themes/metro/easyui.css">
<link rel="stylesheet" type="text/css" href="../../js/jquery-easyui-1.4.3/themes/icon.css">
<script type="text/javascript" src="../../js/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../js/jquery-easyui-1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="../../js/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>

<script>

//value:绑定列的所有值,row:整个datagrid的所有行,index:绑定列的下标
function planUrl(value,row,index){
if(value){
return "<a href=http://www.baidu.com?code="+row.code +">"+value+"</a>";
}
}
</script>

最后,显示的效果是这样的

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: