jQuery Datatables显示html内容

Sam*_*uGG 8 html jquery server-side datatables

我的页面上有一个jquery数据表,它使用服务器端处理来检索数据.在这种情况下,其中一列包含html内容,因此我的服务器响应如下所示:

"aaData": [ [1, "aaa", "<span class="myclass">html here</span>" ], ...
Run Code Online (Sandbox Code Playgroud)

我尝试过

"aoColumnDefs": [ "aTargets":[2], "sType": "html" }
Run Code Online (Sandbox Code Playgroud)

但我仍然看到单元格内容好像是纯字符串.我能做什么?

Sam*_*uGG 8

制作了一个有效的版本

"aoColumnDefs": [ 
    { "aTargets": [2], 
      "sType": "html", 
      "fnRender": function(o, val) { 
          return $("<div/>").html(o.aData[2]).text();
      } 
    }
]
Run Code Online (Sandbox Code Playgroud)

用jQuery解码回html.


小智 6

对于新的数据表版本,我更新了SamuGG的答案:

"aoColumnDefs": [ {
                     "aTargets": [ 5 ],
                     "mRender": function ( data, type, full ) {
                      return $("<div/>").html(data).text(); 
                      }
            } ]
Run Code Online (Sandbox Code Playgroud)