为插件JQuery DataTables添加按钮行

Tie*_*ech 1 jquery jquery-plugins datatables

我正在使用插件"DataTables",我想逐行添加图像,当用户点击时,调用另一个网址.

我按照www.datatables.net的例子,但是给出了以下错误:

DataTables warning(table id ='myDataTable'):从第0行的数据源请求未知参数'4'.

记录显示在屏幕上

<h2>Index</h2>

<script type="text/javascript">
    $(document).ready(function () {

        var oTable = $('#myDataTable').dataTable({
            "bServerSide": true,
            "sAjaxSource": "AjaxHandler",
            "bProcessing": true,
            "sPaginationType": "full_numbers",   
            "aoColumns": [
                        { "mDataProp": "ID", "bSortable": false },
                        { "mDataProp": "Nome", "sTitle": "Identificação do produto" },
                        { "mDataProp": "Address", "sTitle": "Descrição do produto" },
                        { "mDataProp": "Town" },
                        { "fnRender": function (o) {return '<a href=/Produto/Detalhar/' + o.aData[0] + '>' + 'More' + '</a>';}} 
            ],
        });
    });
</script>


<table id="myDataTable" class="display">
    <thead>
        <tr>
            <th>ID</th>
            <th>Company name</th>
            <th>Address</th>
            <th>Town</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody> 
    </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

Dan*_*sco 5

我正在使用dataTables版本1.10.0-dev,并且接受的解决方案对我不起作用,因为o.aData未定义.相反,我拥有json对象的所有属性,我将在o中返回服务器端.所以这是我的解决方案:

$(document).ready(function () {
    var oTable = $('#myDataTable').dataTable({
        "bServerSide": true,
        "sAjaxSource": "AjaxHandler",
        "bProcessing": true,
        "sPaginationType": "full_numbers",
        "aoColumns": [
            { "mData": "ID", "bSortable": false },
            { "mData": "Nome", "sTitle": "Identificação do produto" },
            { "mData": "Address", "sTitle": "Descrição do produto" },
            { "mData": "Town" },
            {
                "mData": null,
                "bSortable": false,
                "mRender": function (o) { return '<a href=/Produto/Detalhar/' + o.Id + '>' + 'More' + '</a>'; }
            }
        ]
    });
});
Run Code Online (Sandbox Code Playgroud)

我不知道这是否取决于新版本的dataTables或其他配置(但我的表格配置方式相同......).