Easyui-datagrid 給標題列加上超連結(MVC3.0應用程式中),easyuidatagrid

來源:互聯網
上載者:User

Easyui-datagrid 給標題列加上超連結(MVC3.0應用程式中),easyuidatagrid

    在接觸一項新東西時,首先就給了自己一種錯覺,“肯定很難,肯定實現不了”,所以就根據任務標題連結到任務詳情頁這個功能,就一拖再拖,今天終於對自己狠了狠心,將其完成了。

       現在的知識也進入了快餐社會,先讓讀者看看是否是自己想要的效果!

 

點擊標題後出現的頁面是:我們可以根據任務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的得到任務實體,返回到介面中,請讀者自行完成,或看我之後的文章!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.