给Jquery easyui 的datagrid 每行增加操作链接

本文详细介绍了如何在Easy-UI Datagrid中通过自定义formater函数添加超链接,实现消息列表中每行后面的操作链接,如查看、修改、删除等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景

  我们都知道Jquery的Easy-UI的datagrid可以添加并且自定义Toolbar,这样我们选择一行然后选择toolbar的相应按钮就可以对这行的数据进行操作。但实际项目里我们可能需要在每行后面加一些操作链接,最常见的就是比如“修改”、“删除”、“查看”之类。如下图:

          

  凡事都怕但是!Easy-UI的Datagrid没有直接添加link的属性。查看Easy-UI的帮助文档,看到一个formater:格式化函数,可以对某一行进行格式化,然后通过URL+ID的方式把页面跳转到新页面.


解决方法


  1、在需要添加超链接的列进行格式化处理(formater:格式化函数),如下:
    
<th data-options="field:'Title',width:150,align:'center',formatter: rowformater">消息名称</th>
  2、根据documentation的描述,formatter的格式化函数有3个parameters,分别是:
    value: the field value,也就是field:'id'。
    rowData: the row record data。就是这一行的Json数据,包括你已经选择在Datagrid上显示的内容,和没显示的内容。
    rowIndex: the row index.当前行的Index。
 通过这个函数来执行相应的javaScript函数就可以达到目的.

  3、脚本函数&前台代码


[javascript]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <script type="text/javascript">  
  2.     //查看详情  
  3.     function rowformater(value, row, index) {  
  4.         return "<a href='NewsDetial.aspx?NoticeID=" + row.ID + "' target='_block'>" + row.Title + "</a>";  
  5.     }  
  6.   
  7. </script>  


[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <table id="dg" title="已发布消息" class="easyui-datagrid" style="width: 1090px; height: 430px; padding-left: 200px;" data-options="rownumbers:true,url:'EasyUITotalNews.ashx/ProcessRequest',pageSize:5,pageList:[5,10,15,20],method:'get',toolbar:'#tb' ," toolbar="#toolbar" pagination="true" rownumbers="true" fitcolumns="true" striped="true" singleselect="true">  
  2.   
  3.             <thead>  
  4.                  <tr>  
  5.                     <th data-options="field:'ck',checkbox:true"></th>  
  6.                     <th data-options="field:'ID',width:150,align:'center'">消息编号</th>  
  7.                     <th data-options="field:'Title',width:150,align:'center',formatter: rowformater">消息名称</th>  
  8.                     <th data-options="field:'PublishDepart',width:150,align:'center'">发送单位</th>  
  9.                     <th data-options="field:'ReceiveDepart',width:150,align:'center'">接收单位</th>  
  10.                     <th data-options="field:'PublishTime',width:150,align:'center'">发送时间</th>  
  11.                     <th data-options="field:'NoticeState',width:80,align:'center'">是否读取</th>  
  12.                 </tr>  
  13.             </thead>  
  14.         </table>  

  4、效果

      


小结

  由于Easy-UI本身就是Jquery封装的库,所以其本质还是javascript.虽然本身没有link属性,但是通过其定义的属性或是方法,按照其格式构造一个javascript函数语句即可。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值