Datatables 获取ajax返回的数据
ajaxJson=noticeMainDT.ajax.json();
noticeMainDT = $("#notice_mainDataTables").DataTable({
ajax: {
url: "../wj_news/queryById4DT",
type: "POST",
data: function (d) {
d.search = "";
d.userId = gLoginInfo.userId;
d.menuId = noticeMenuId;
d.orderId = gLoginInfo.roleId;
d.newsType = 2;
}
},
columns: [{
data: null,
targets: 0
}, {
data: "newsText",
render: function (data, type, row) {
data = data.replace(/<.*?>/ig, "");
data = data.replace(/ /ig, "");
data = data.substring(0, 10) + '...';
return "<div><a href='javascript:void(0)' onclick='$.readNews(" + JSON.stringify(row) + ")'>" + data + "</a></div>";
}
}],
dom: "<'row'<'col-md-4'><'.col-md-8'>r>t<'row'<'col-md-6'><'col-md-6'>>",
initComplete: function () {
var noticeJson = noticeMainDT.ajax.json();
},
processing: true,
serverSide: true,
ordering: false,
select: false,
autoFill: true,
displayLength: 10,
lengthMenu: [[5, 10, 15, 20, 50, 100, 150, -1], [5, 10, 15, 20, 50, 100, 150, "All"]],
language: {
url: "zh_cn.json"
},
fnDrawCallback: function () {// 序号自增回调函数
var api = this.api();
var startIndex = api.context[0]._iDisplayStart;
api.column(0).nodes().each(function (cell, i) {
cell.innerHTML = startIndex + i + 1;
});
}
});