Easyui-datagrid 给标题列加上超链接(MVC3.0应用程序中)

    在接触一项新东西时,首先就给了自己一种错觉,“肯定很难,肯定实现不了”,所以就根据任务标题链接到任务详情页这个功能,就一拖再拖,今天终于对自己狠了狠心,将其完成了。

       现在的知识也进入了快餐社会,先让读者看看是否是自己想要的效果!

点击标题后出现的页面是:我们可以根据任务ID得到具体的任务,返回到界面显示给用户

由于MVC应用程序所走的路线是有所不同的,所以我们按断点调试走一遍代码:

  1. controller中

#region 获得分页数据+ 刘颖 2015-1-6

        public JsonResult LoadPages()
        {
            //1、具体操作-调用后台方法,接收从后台传过来的--赋值
            //调用假数据模仿
            int pagesize =Request["rows"] == null ? 10 : int.Parse(Request["rows"]);
            int pagenum =Request["page"] == null ? 1 : int.Parse(Request["page"]);
           //需要根据页容量和页码进行查询,查询出来的数据,直接赋给底下dgmode对象的rows,
            //另外还需要进行页码总行数查询,查询出来的数据需要赋给total
            //查询任务信息
            List<Task> lsTask = newList<Task>();
            int total = 0;
     //查询任务信息 使用分页方法
            lsTask =basictaskService.LoadPageTask(pagesize, pagenum, out total);

            //2 生成规定格式的 json字符串发回 给 异步对象
            //生成符合EasyUi格式的数据

            DataGridView dgModel = newDataGridView()
            {
                total = total,
                rows = lsTask,
                footer = null
            };
            //2.0返回到前台的信息

            return Json(dgModel,JsonRequestBehavior.AllowGet);

        }
        #endregion
  1. View中:先看页面实现:当然也要引用easyui中的5个文件到页面中(具体路径可能不一致)
    <scriptsrc="../../Content/jquery-easyui-1.3.2/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript"src="../../Content/jquery-easyui-1.3.2/jquery.easyui.min.js"></script>
    <link rel="stylesheet"type="text/css"href="../../Content/jquery-easyui-1.3.2/themes/default/easyui.css">
    <link rel="stylesheet"type="text/css"href="../../Content/jquery-easyui-1.3.2/themes/icon.css">
    <link rel="stylesheet"type="text/css"href="../../Content/jquery-easyui-1.3.2/demo/demo.css">

页面具体实现代码

  1. url定义用于接收controller返回的数据
<table id="dg"class="easyui-datagrid" title="任务信息"data-options="rownumbers:true,singleSelect:true,autoRowHeight:true,pagination:true,url:'@ViewData["url"]'"toolbar:"#tb" >
            <thead>
                <tr>
                    <thdata-options="field:'ck',checkbox:true"></th>
                    <thdata-options="field:'TaskID'" style="width:80px">任务ID</th>
                    <thdata-options="field:'TaskCode'" style="width: 80px; text-align:right">任务编号</th>
                    <thdata-options="field:'TaskTitle',formatter: titleformater" style="width: 100px">任务标题</th>
                    <thdata-options="field:'TaskContent'" style="width:80px">任务内容</th>
                    <thdata-options="field:'AssignStartTime'" style="width: 80px;text-align: right">任务分配时间</th>
                    <thdata-options="field:'ExpectFinish'" style="width: 100px;text-align: right">任务期望完成时间</th>
                    <thdata-options="field:'RemindType'" style="width:110px">任务提醒方式</th>
                    <thdata-options="field:'Note'" style="width:110px">任务备注</th>
                    <thdata-options="field:'Operator'" style="width:110px">任务添加者</th>

                </tr>
            </thead>
        </table>
  1. 我们在标题列使用格式化方法:
 <thdata-options="field:'TaskTitle',formatter: titleformater" style="width: 100px">任务标题</th>

格式化方法在页面javascript中如下:easyui的datagrid的每个单元格有三个参数组成,(值,行索引,列索引)

<scripttype="text/javascript">
//将href导向控制器TaskDetails下Index中
    function titleformater(value, row, index) {
        return "<ahref='TaskDetails/Index?TaskID=" + row.TaskID + "'target='_blank'>" + value + "</a>";

    }
</script>

根据任务ID的得到任务实体,返回到界面中,请读者自行完成,或看我之后的文章!

时间: 2024-08-27 17:25:48

Easyui-datagrid 给标题列加上超链接(MVC3.0应用程序中)的相关文章

EasyUI DataGrid动态修改列标题

var option = $('#tt').datagrid("getColumnOption", "列名") option.title = "新的列名"; $('#tt').datagrid(); 其实就是先获取到列的数据信息,修改,重置. 看下官方的说明,如下,

easyui datagrid 表格组件列属性formatter和styler使用方法

明确单元格DOM结构 要想弄清楚formatter和styler属性是怎么工作的,首先要弄清楚datagrid组件内容单元格的DOM接口,注意,这里指的是内容单元格,不包括标题单元格,标题单元格的结构有所区别.我们所有内容单元格的默认DOM结构如下: 1 2 3 4 5 <td field="code">     <div style="text-align:left" class="datagrid-cell datagrid-cell

EasyUI datagrid动态添加列

任务描述:根据用户选择时间段,生成列数据,如图 一.先定义好datagrid固定的数据列 <script type="text/javascript"> $(document).ready(function () { $("#td_Radio").datagrid({ striped: true, border: true, iconCls: 'icon-edit', //图标 singleSelect: true, autoRowHeight: tru

Easyui Datagrid相同连续列合Demo之三

效果图: html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Merge Cells for DataGrid - jQuery EasyUI Demo</title> <link rel="stylesheet" type="text/css" href="../../themes

Easyui Datagrid相同连续列合Demo(二)

效果图: html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Merge Cells for DataGrid - jQuery EasyUI Demo</title> <link rel="stylesheet" type="text/css" href="../../themes

Easyui datagrid 显示隐藏列

html: <div style="float: left; width: 1450px; height:auto;  "> <table id="List" class="easyui-datagrid" title="基站信息列表" width="1450px" style="height:580px;" data-options="rownumbers:

easyui datagrid自定义按钮列,即最后面的操作列

在很多时候我们要在表格的最后添加一列操作列,easyUI貌似没有提供种功能,不过没关系,我们可以自定义来实现首先是HTML部分 <table id="tt" class="easyui-datagrid" style="width:100%;height:554px"             singleSelect="false"              fitColumns="true"    

easyui datagrid editor 特定列disabled

//编辑表格   function editRow(rowIndex) {       $('#tt').datagrid('cancelEdit', lastIndex);       $('#tt').datagrid('beginEdit', rowIndex);       lastIndex = rowIndex;       $('#tt').datagrid('getEditor', { index: rowIndex, field: 'VAL_NAME' }).disabled(

EasyUI datagrid 实现标题居中,内容居左的方法

源码中内容: cell.css("text-align",(col.halign||col.align||"")); 这里有个属性挺眼熟 : col.align 前面还有一个: col.halign 可以使用此属性实现该功能.代码如下: <th data-options="field:'title', width:400,align:'left' , halign: 'center'">标题</th> 其中 align:'