给Jquery easyui 的datagrid 每行增长操做连接

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

          bubuko.com,布布扣

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


解决方法


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

  三、脚本函数&前台代码java

    <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="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">

            <thead>
                 <tr>
                    <th data-options="field:'ck',checkbox:true"></th>
                    <th data-options="field:'ID',width:150,align:'center'">消息编号</th>
                    <th data-options="field:'Title',width:150,align:'center',formatter: rowformater">消息名称</th>
                    <th data-options="field:'PublishDepart',width:150,align:'center'">发送单位</th>
                    <th data-options="field:'ReceiveDepart',width:150,align:'center'">接收单位</th>
                    <th data-options="field:'PublishTime',width:150,align:'center'">发送时间</th>
                    <th data-options="field:'NoticeState',width:80,align:'center'">是否读取</th>
                </tr>
            </thead>
        </table>


  四、效果app

      bubuko.com,布布扣


小结

  因为Easy-UI自己就是Jquery封装的库,因此其本质仍是javascript.虽然自己没有link属性,可是经过其定义的属性或是方法,按照其格式构造一个javascript函数语句便可。函数

相关文章
相关标签/搜索