[英]How to disable sorting on specific column while searching is functional
我使用DataTable( http://www.datatables.net )來獲得所需的功能,包括對列進行排序以及分別從表標題中搜索列。 初始化如下,返回api並實現搜索功能。
$('#table2')。DataTable()
現在的問題是,當我必須禁用復選框的排序功能並且必須使用以下代碼行時。 $('#table2').dataTable( { "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 0 ] } ] } );
它確實對列應用了禁用的排序,但是列內的搜索功能也不起作用。 有什么方法可以在DataTable({something})中傳遞任何參數以禁用對第一列的排序,或者請幫助我組合(api和jquery對象)方法以實現所需的功能。 $('#table2').DataTable(); $('#table2').dataTable();
<table class="table table-striped draggable sortable dataTable" id="table2">
<thead>
<tr>
<th class="text-center"> <input class="check_box_all no-sort" id="check_all" type="checkbox" title="Check All"></th>
<th class="text-center">Company Name </th>
</tr>
</thead>
<tbody>
<tr class="odd gradeX">
<td class="text-center"><input type="checkbox" class="check_box"></td>
<td class="text-center">Med Assets Company</td>
</tr>
</tbody>
此代碼段使表標題中的輸入字段可供搜索
$('#table2 thead th').slice(3).each(function () {
var title = $('#table2 thead th').eq($(this).index()).text();
$(this).html('<input type="text" placeholder="' + title + '" />');
});
數據表初始化
var table = $('#table2').DataTable({
"dom": 'C<"clear">lfrtip',
"sPaginationType": "full_numbers",});
應用搜索
var tableResult = table.columns().eq(0);
if (tableResult !== null) {
tableResult.each(function (colIdx) {
$('input', table.column(colIdx).header()).on('keyup change', function () {
table
.column(colIdx)
.sort()
.search(this.value)
.draw();
});
});
}
請在選中復選框時檢查jsfiddle,將其完全弄亂https://jsfiddle.net/sxgd0thm/
$('#example').dataTable( {
"aoColumnDefs": [
{ "bSearchable": true, "aTargets": [ 0,1,2,3,4,5 ] }
] } );
嘗試使用“ bSearchable”進行允許的列搜索
$('#table2').dataTable({
"dom": 'C<"clear">lfrtip',
"sPaginationType": "full_numbers",
"aoColumnDefs": [
{ "bSearchable": false, "aTargets": [ 0 ] },
{"bSortable": false, "aTargets": [ 1 ]}
]});
你可以試試這個嗎
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.