首页 > jquery.datatables.min.js 表格使用问题

jquery.datatables.min.js 表格使用问题

javascript$(function() {
    var table = $('#table2').dataTable( {
        data: articleCategorys,
        "columns": [
            { "data": "articleCategoryId" },
            { "data": "title" },
            { "data": "alias" },
            { "data": "parentId" },
            {
                "className":      'table-action',
                "orderable":      false,
                "data":           null,
                "defaultContent": '<a href="javascript:void(0);" class="edit-row"><i class="fa fa-pencil"></i></a><a href="javascript:void(0);" class="delete-row"><i class="fa fa-trash-o"></i></a>'
            }
        ],
        "sPaginationType": "full_numbers",
        "columnDefs": [ {
            "orderable": false,
            "targets": [1,2,3,4]
        } ],
        "oLanguage": {
            "sLengthMenu": "每页显示 _MENU_ 条记录",
            "sZeroRecords": "抱歉, 没有找到",
            "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
            "sInfoEmpty": "没有数据",
            "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
            "sSearch": "搜索:",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            },
            "sProcessing": "<div id='status'><i class='fa fa-spinner fa-spin'></i></div>"
        }
    } );

怎么把 { "data": "articleCategoryId" } 放到 "defaultContent" 里面的连接里去

也就是 <a href="javascript:void(0);" class="edit-row"> 变成 <a href="/edit/{articleCategoryId}/" class="edit-row">

也就是 defaultContent 怎么加载 data 里面的数据


查下API,应该有个render函数,旧版本叫fnRender,用这个函数替换你现有的defaultContent

fnRender: function(obj) {
  return '<a href="' + obj.aData[4] + '">xxx</a>';
}

你的版本我猜测是:

render: function(obj) {
  return '<a href="' + obj.data[4] + '">xxx</a>';
}
【热门文章】
【热门文章】