zoukankan      html  css  js  c++  java
  • 给Jquery easyui 的datagrid 每行添加操作链接

    背景

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

              

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


    解决方法


      1、在须要加入超链接的列进行格式化处理(formater:格式化函数),例如以下:
        
    <th data-options="field:'Title',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、脚本函数&前台代码


        <script type="text/javascript">
            //查看详情
            function rowformater(value, row, index) {
                return "<a href='NewsDetial.aspx?

    NoticeID=" + row.ID + "' target='_block'>" + row.Title + "</a>"; } </script>



    <table id="dg" title="已公布消息" class="easyui-datagrid" style=" 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">
    
                <thead>
                     <tr>
                        <th data-options="field:'ck',checkbox:true"></th>
                        <th data-options="field:'ID',150,align:'center'">消息编号</th>
                        <th data-options="field:'Title',150,align:'center',formatter: rowformater">消息名称</th>
                        <th data-options="field:'PublishDepart',150,align:'center'">发送单位</th>
                        <th data-options="field:'ReceiveDepart',150,align:'center'">接收单位</th>
                        <th data-options="field:'PublishTime',150,align:'center'">发送时间</th>
                        <th data-options="field:'NoticeState',80,align:'center'">是否读取</th>
                    </tr>
                </thead>
            </table>
    

      4、效果

         


    小结

      因为Easy-UI本身就是Jquery封装的库,所以其本质还是javascript.尽管本身没有link属性。可是通过其定义的属性或是方法,依照其格式构造一个javascript函数语句就可以。




  • 相关阅读:
    值得收藏的146条经典民间偏方[转]
    删除暴风文件夹内的stormliv.exe
    【转】VLAN技术浅谈
    [转载]双击.dsw文件时另开VC6.0,而不会关掉原来已打开的项目的解决办法(转载)
    JVM系列1:Java内存区域
    并发系列3:Lock锁以及核心类AQS
    并发系列1:并发基础知识
    JVM系列2:垃圾收集器与内存分配策略
    JVM系列3:类加载机制
    源码解析之AQS源码解析
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/7305541.html
Copyright © 2011-2022 走看看