我是DataTable的新手。在这里,当我单击与该行关联的视图链接时,我试图获取该行的第一个单元格值,而不是获取的[object object]值。

这是我的代码
        

        $(document).ready(function() {


            // Delete a record
            $('#example').on('click', 'a.editor_view', function (e) {
                e.preventDefault();
                var rowIndex = oTable.fnGetPosition( $(this).closest('tr')[0] );
                 aData = oTable.fnGetData($(this).parents('tr')[0]);
                alert(aData);
            } );

            // DataTables init

            var oTable=$('#example').dataTable( {
                "sDom": "Tfrtip",
                "sAjaxSource": "php/browsers.php",
                "aoColumns": [
                    { "mData": "browser" },
                    { "mData": "engine" },
                    { "mData": "platform" },
                    { "mData": "grade", "sClass": "center" },
                    {
                        "mData": null,
                        "sClass": "center",
                        "sDefaultContent": '<a href="" class="editor_view">view</a> / <a href="" class="editor_remove">Delete</a>'
                    }
                ]
            } );
        } );


HTML表格:

<table cellpadding="0" cellspacing="0" border="0" class="display" id="example" width="100%">
<thead>
    <tr>
        <th width="30%">Browser</th>
        <th width="20%">Rendering engine</th>
        <th width="20%">Platform(s)</th>
        <th width="14%">CSS grade</th>
        <th width="16%">Admin</th>
    </tr>
</thead>
<tfoot>
    <tr>
        <th>Browser</th>
        <th>Rendering engine</th>
        <th>Platform(s)</th>
        <th>CSS grade</th>
        <th>Admin</th>
    </tr>
</tfoot>




现在,当我单击视图时,我需要导航到另一个页面,其ID为
view.php?id = 125

谢谢

最佳答案

$('#example').on('click', 'a.editor_view', function (e) {
  e.preventDefault();
  var rowIndex = oTable.fnGetPosition( $(this).closest('tr')[0] );
  aData = oTable.fnGetData(rowIndex,0);
  alert(aData);
} );


从api文档中:

fnGetData
输入参数:
{int | node}:TR行节点,TD / TH单元节点或整数。如果将其指定为TR节点,则将返回整行的数据源。如果给出为TD / TH单元节点,则将自动计算iCol并返回该单元的数据。如果以整数形式给出,则将其视为该行的aoData内部数据索引(请参阅fnGetPosition)和所用该行的数据。

{int}:要获取其数据的可选列索引。

07-25 22:05
查看更多