0

How to get from mData property a given cells value? I have the following code with the table initialization, I add dynamically cell values to my table specific column and I would like to define the data-id using the value of clicked rows hidden cell. If I alert (source) I can see the comma separated data string. I would like to hole up the first value.

/* Table initialisation */
$(document).ready(function() {

    var oTable = $('#example').dataTable( {
        "aoColumnDefs": [ {
          "aTargets": [ 15 ],
          "mData": function ( source, type, val ) {
            alert(source);
            return "<a id='MyModal' data-id='" + source.my-id + "' href='#'>Edit</a> | <a href ='action.php?id='>Delete</a>";
          }
        } ]
      } );  
} );
4

2 回答 2

1

如果我说对了val[0]val[1]等等……就是您要找的东西

另外,我认为您应该替换mData替换为mRender

"mRender": function ( source, type, val ) {
            alert(source);
            return "<a id='MyModal' data-id='" + source.my-id + "' href='#'>Edit</a> | <a href ='action.php?id='>Delete</a>";
          }
于 2013-01-07T16:26:21.180 回答
1

是的。您应该使用 mRender,而不是使用 mData。

mData 和 mRender 之间的区别在于您不应该同时使用它们。如果您想根据条件操作模型并根据您要渲染页面的条件,则使用 mRender,但在 mData 中,您直接在列中绑定模型。

于 2015-05-20T07:12:23.960 回答