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

首先,我我们要有一个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>

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

posted @ 2016-04-01 11:22  小小邪  阅读(2216)  评论(0编辑  收藏  举报