2013-09-20 68 views
0

我想在第一列的每個單元格中創建一個鏈接,但我遇到了一些麻煩。當我使用下面的代碼時,我能夠按照預期在前六列中看到數據。datatables mrender問題asp.net

"aoColumnDefs": 
[ 
    {"mDataProp": "Title","aTargets": [0]}, 
    { "mDataProp": "Body", "aTargets": [1], }, 

    { "mDataProp": "Feelings", "aTargets": [2] }, 
    { "mDataProp": "Tags", "aTargets": [3] }, 

    {"mDataProp": "Published","aTargets": [4]}, 

    { "mDataProp": "LastRevised", "aTargets": [5] }, 


    { 
     "mDataProp": "Id", 

     "bVisible": false, 

     "aTargets": [6] 
    }, 

然而,當我嘗試創建基於這個例子中,標題欄鏈接:http://datatables.net/release-datatables/examples/advanced_init/column_render.html

這是我想出了:

 "aoColumnDefs": 
    [ 
    {"mRender": function (data, type, row) { 

    return '<a href="@Url.Action("Details", "Table")/"' + row[6]+'">'+data+'</a>'; 
        }, 
       "aTargets": [0] 
       }, 


     { "mDataProp": "Body", "aTargets": [1], }, 

     { "mDataProp": "Feelings", "aTargets": [2] }, 
     { "mDataProp": "Tags", "aTargets": [3] }, 

     { 
      "mDataProp": "Published", 

      "aTargets": [4] 
     }, 

     { "mDataProp": "LastRevised", "aTargets": [5] }, 


     { 
      "mDataProp": "Id", 

      "bVisible": false, 

      "aTargets": [6] 
     }, 

我想要顯示的內容那些以前在標題欄中的鏈接指向每個項目的詳細信息視圖,但上述內容不起作用。

回答

0

想通了。有很多錯誤。

  1. mDataProp需要呈現的列。
  2. 行不是數組。 「斜槓
  3. mrender後支持1.9.4版本開始

下面是正確的列定義‘

  • 有一個不必要的標題’(第一)列:

     { 
    
    "mDataProp": "Title", 
    
    "mRender": function (data, type, row) { 
           return '<a href="@Url.Action("Details", "Table")/' + row.Id+'">'+data+'</a>';}, 
    "aTargets": [0] 
          },