Javascript Datatable aoColumnDefs未按预期工作
我面临数据表的问题Javascript Datatable aoColumnDefs未按预期工作,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,我面临数据表的问题 <table id="example1" class="table table-bordered table-striped"> <thead> <tr> <c:forEach items="${D
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<c:forEach items="${Details.columns}" var="column">
<th>${column.columnTitle}</th>
</c:forEach>
</tr>
</thead>
<tfoot>
<tr>
<c:forEach items="${Details.columns}" var="column">
<th></th>
</c:forEach>
</tr>
</tfoot>
<tbody>
<c:forEach items="${Details.callList}" var="call">
<tr>
<c:forEach items="${call.attributes}" var="attribute">
<td>${attribute.value}</td>
</c:forEach>
</tr>
</c:forEach>
</tbody>
</table>
$("#example1").dataTable({
'sDom': '"top"i',
//"aoColumnDefs": [{ "bSearchable": true, "aTargets": [1] }],
"bPaginate" : true,
"bLengthChange" : false,
//"bFilter" : true,
"bSearchable": true,
"bSort" : true,
"bInfo" : true,
"bAutoWidth" : false,
"iDisplayLength": 5
//}).columnFilter({"aoColumns": [{ "type": "text" }, { "type": "text" }, null]});
}).columnFilter({"aoColumnDefs": [{ "bSearchable": true, "aTargets": [2] }]});
${column.columnTitle}
${attribute.value}
$(“#示例1”).dataTable({
“sDom”:“top”i,
//“aoColumnDefs”:[{“BSearcable”:true,“aTargets”:[1]}],
“bPaginate”:对,
“bLengthChange”:false,
//“bFilter”:没错,
“可听”:是的,
“bSort”:正确,
“宾福”:没错,
“bAutoWidth”:假,
“iDisplayLength”:5
//}).columnFilter({“aoColumns”:[{“类型”:“文本”},{“类型”:“文本”},null]});
}).columnFilter({“aoColumnDefs”:[{“BSearcable”:true,“aTargets”:[2]}]});
从上面的片段中。。我正在尝试仅删除最后一列的筛选/搜索
这里的“aoColumns”按预期工作-它删除了我编码的最后一列中的过滤器,
但是,我无法使用“aoColumns”。由于此表中的列是动态/可配置的,因此我很难每次都更改代码
如果有人能在这里帮助我,我将不胜感激
谢谢,这就是我使用Datatables的方式,它的工作方式很有魅力。我不在客户端进行排序,而是在服务器端使用AJAX进行排序,但是表的配置应该是相同的,除了“bServerSide=true”。让我知道这是否解决了您的问题:
var oTable = $('#tblMainTable').dataTable({
"searching": false,
"bStateSave": true,
"fnStateSave": function (oSettings, oData) {
localStorage.setItem('jobTitlesDataTables', JSON.stringify(oData));
},
"fnStateLoad": function (oSettings) {
return JSON.parse(localStorage.getItem('jobTitlesDataTables'));
},
"pagingType": "full_numbers",
"bLengthChange": false,
"bAutoWidth": false,
"iDisplayLength": 2000,
"bServerSide": true, // server side
"sAjaxSource": BASE_URL + "Job/GetJobTitleMappingDTOs", // AJAX URL
"bProcessing": true,
"fnServerData": function (sSource, aoData, fnCallback, oSettings) {
// send data from client-side to server-side
aoData.push({ "name": "IsMapped", "value": $("#bdgIsMapped").data("selected") });
aoData.push({ "name": "IsSearchableOption", "value": $("#bdgIsSearchable").data("selected") });
aoData.push({ "name": "timestamp", "value": new Date().getTime() }); // Added to avoid caching in some IE versions.
oSettings.jqXHR = $.ajax({
"dataType": 'json',
"type": "GET",
"url": sSource,
"data": aoData,
"cache": false,
"success": function (json) {
// shows records count next to the top title
if (json.iTotalRecords > 0) {
$("#resultsDescription").text(" - " + json.iTotalRecords + " rows.");
}
else {
$("#resultsDescription").text(" - No results.");
}
// shows paginator when necessary
if (json.iTotalRecords > json.iDisplayLength) {
$(".dataTables_paginate").show();
}
else {
$(".dataTables_paginate").hide();
}
$("#isFirstSearch").val("false");
fnCallback(json);
}
});
},
"aoColumnDefs": [
{
sType: "numeric",
mData: "RowNumber",
aTargets: [0],
mRender: function (data, type, full) {
// this is for custom rendering a column just in case you need it
// 'full' is the row's data object, and 'data' is this column's data
return '<span class="RowNumber">' + full.RowNumber + '</span>';
}
},
{
sType: "numeric",
mData: "JobTitleId",
aTargets: [1],
mRender: function (data, type, full) {
// 'full' is the row's data object, and 'data' is this column's data
return '<span class="EditableJobTitleId" data-job-title-id="' + full.JobTitleId + '">' + full.JobTitleId + '</span>';
}
},
{
sType: "string",
mData: "JobTitle",
aTargets: [2]
}
],
"order": [[1, "asc"]]
});
var-oTable=$('tblMainTable')。数据表({
“搜索”:错误,
“bStateSave”:正确,
“fnStateSave”:函数(oSettings,oData){
setItem('jobTitlesDataTables',JSON.stringify(oData));
},
“fnStateLoad”:功能(oSettings){
返回JSON.parse(localStorage.getItem('jobTitlesDataTables');
},
“pagingType”:“完整编号”,
“bLengthChange”:false,
“bAutoWidth”:假,
“iDisplayLength”:2000,
“bServerSide”:true,//服务器端
“sAjaxSource”:BASE_URL+“Job/GetJobTitleMappingDTOs”,//ajaxURL
“bProcessing”:正确,
“fnServerData”:函数(sSource、aoData、fnServerData回调、oSettings){
//将数据从客户端发送到服务器端
推送({“name”:“IsMapped”,“value”:$(“#bdgIsMapped”).data(“selected”)});
推送({“名称”:“IsSearchableOption”,“值”:$(“#bdgisearchable”).data(“选定”)});
aoData.push({“name”:“timestamp”,“value”:new Date().getTime()});//添加此项以避免在某些IE版本中缓存。
oSettings.jqXHR=$.ajax({
“数据类型”:“json”,
“类型”:“获取”,
“url”:sSource,
“数据”:aoData,
“缓存”:false,
“成功”:函数(json){
//显示顶部标题旁边的记录计数
如果(json.iTotalRecords>0){
$(“#resultsDescription”).text(“-”+json.iTotalRecords+“rows”);
}
否则{
$(“#resultsDescription”).text(“-无结果”);
}
//必要时显示分页器
if(json.iTotalRecords>json.iDisplayLength){
$(“.dataTables_paginate”).show();
}
否则{
$(“.dataTables_paginate”).hide();
}
$(“#isFirstSearch”).val(“false”);
fn回调(json);
}
});
},
“aoColumnDefs”:[
{
sType:“数字”,
mData:“行数”,
数据目标:[0],
mRender:功能(数据、类型、完整){
//这用于自定义渲染列,以备需要
//“full”是行的数据对象,“data”是此列的数据
返回“”+full.RowNumber+“”;
}
},
{
sType:“数字”,
mData:“JobTitleId”,
数据目标:[1],
mRender:功能(数据、类型、完整){
//“full”是行的数据对象,“data”是此列的数据
返回“”+full.JobTitleId+“”;
}
},
{
sType:“字符串”,
mData:“职务头衔”,
目标:[2]
}
],
“订单”:[[1,“asc”]]
});
您能告诉我如何禁用DataTable中特定列的搜索/筛选功能吗?上面是我的代码,它没有工作,所以..我不知道如何使一列不可搜索。我更喜欢为所有列停用该功能,并在表外定义自定义过滤器,因为它给了我更大的灵活性,尽管它需要更多的工作。