0
我正在使用datatables服務器端,並且當我想要使用列篩選器搜索服務器端數據時出現問題,因爲渲染值與數據庫字段值不匹配。例如:在我的數據庫中,狀態列中有0和1。在我的數據表中,我顯示狀態列和渲染來獲得這個:if status = 0,然後我將顯示禁用,如果我有1,我會顯示啓用。使用渲染Jquery數據表格篩選
這裏是我的代碼片段:
$(document).ready(function() {
/* ----------------------------------------------------- */
/* ----------------- DATATABLES HISTORY ---------------- */
/* ----------------------------------------------------- */
$('#historyTable').DataTable({
dom: "t<'col-sm-5'i><'col-sm-7'p>",
autoWidth: true,
aaSorting: [[1, 'asc']],
serverSide: true,
lengthChange: false,
ajax: {
url: 'history',
method: 'POST'
}
columns: [
{data: "id"},
{data: "name", orderData: [ 1, 0 ]},
{data: "status", render: renderStatus, orderData: [ 2, 0 ]}
]
});
var historyTable = $('#historyTable').DataTable();
// Render status
function renderStatus(data, type, dataToSet){
if(dataToSet.status == '1'){
return "enabled";
}else{
return "disabled";
}
}
// Global search
$('#historySearch').on('keyup', function(){
historyTable.search($(this).val()).draw();
});
// Length menu
$('#historyMenu').on('change', function(){
historyTable.page.len($(this).val()).draw();
});
// Setup - add a text input to each footer cell
$('#historyTable tfoot td').each(function() {
var title = $('#historyTable tfoot td').eq($(this).index()).text();
$(this).html('<input type="text" />');
});
// Apply the search
historyTable.columns().eq(0).each(function (colIdx) {
$('input', historyTable.column(colIdx).footer()).on('keyup change', function() {
historyTable
.column(colIdx)
.search(this.value)
.draw();
});
});
});
你知不知道我該怎麼做,以配合服務器端值呈現值?
爲什麼要將列名傳遞給服務器? – John