我在html页面上有数据表.在我的Datatable中,我在页脚处进行了按列搜索.此搜索适用于所有列,但有一列包含 Select 选项元素(下拉列表),因此不适用.每次它开始搜索而不是列表的选定值时,它都在搜索所有列表值.
here you can see position search is working fine. its draw match value correctly.
薪资列的列表值包含:-适配器、适配器1、 capacitor 、二极管
But when i type any value which is not present in list then it show correctly, So search is working but it takes all value instead of selected value :-
你能帮我一下吗.
下面是我的代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>BootStrap</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-table.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.3.4/css/select.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://editor.datatables.net/extensions/Editor/css/editor.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/datetime/1.1.2/css/dataTables.dateTime.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/2.2.2/css/buttons.dataTables.min.css">
<!-- <link type="text/css" href="//gyrocode.github.io/jquery-datatables-checkboxes/1.2.12/css/dataTables.checkboxes.css" rel="stylesheet" /> -->
<!-- https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.css -->
</head>
<body>
<div class="container mb-3 mt-3">
<div class="panel panel-default">
<div class="panel-heading"><b> Demo </b> </div>
<div class="panel-body">
<div class="tbl_user_data"><table class="table table-striped table-bordered" id = "mydatatable"
>
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr row_id = "123">
<td></td>
<td><div class="row_data" edit_type="click" col_name="fname">Tiger Nixon</div></td>
<td><div class="row_data" edit_type="click" col_name="pos">Developer</div></td>
<td><div class="row_data" edit_type="click" col_name="off">Edinburgh</div></td>
<td><div class="row_data" edit_type="click" col_name="age">61</div></td>
<td><div class="row_data" edit_type="click" col_name="startdate">2011/04/25</div></td>
<td><div class="row_data" edit_type="lov" col_name="sal">
<select class="example-dropUp" id="selhw">
<option >Adapter</option>
<option selected>Adapter1</option>
<option >Capacitor</option>
<option >Diode</option>
</select>
</div></td>
</tr>
<tr row_id = "124">
<td></td>
<td><div class="row_data" edit_type="click" col_name="fname">Tiger Nixon1</div></td>
<td><div class="row_data" edit_type="click" col_name="pos">System Architect1</div></td>
<td><div class="row_data" edit_type="click" col_name="off">Edinburgh1</div></td>
<td><div class="row_data" edit_type="click" col_name="age">611</div></td>
<td><div class="row_data" edit_type="click" col_name="startdate">2011/04/25</div></td>
<td><div class="row_data" edit_type="lov" col_name="sal">
<select class="example-dropUp" id="selhw">
<option >Adapter</option>
<option >Adapter1</option>
<option selected>Capacitor</option>
<option >Diode</option>
</select>
</div></td>
</tr>
<tr row_id = "125">
<td></td>
<td><div class="row_data" edit_type="click" col_name="fname">Tiger Nixon2</div></td>
<td><div class="row_data" edit_type="click" col_name="pos">System Architect2</div></td>
<td><div class="row_data" edit_type="click" col_name="off">Edinburgh2</div></td>
<td><div class="row_data" edit_type="click" col_name="age">61</div></td>
<td><div class="row_data" edit_type="click" col_name="startdate">2011/04/25</div></td>
<td><div class="row_data" edit_type="lov" col_name="sal">
<select class="example-dropUp" id="selhw">
<option >Adapter</option>
<option >Adapter1</option>
<option >Capacitor</option>
<option selected>Diode</option>
</select>
</div></td>
<tfoot>
<tr>
<th></th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</tbody>
</table>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><b>HTML Table Edits/Upates</b> </div>
<div class="panel-body">
<p>All the changes will be displayed below</p>
<div class="post_msg"> </div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/esm/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
<script src="https://cdn.datatables.net/select/1.3.4/js/dataTables.select.min.js"></script>
<script type="text/javascript" src="/js/bootstrap-table.min.js"></script>
<script src="https://editor.datatables.net/extensions/Editor/js/dataTables.editor.min.js"></script>
<script src="https://cdn.datatables.net/datetime/1.1.2/js/dataTables.dateTime.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.2.2/js/dataTables.buttons.min.js"></script>
<!-- <script type="text/javascript" src="//gyrocode.github.io/jquery-datatables-checkboxes/1.2.12/js/dataTables.checkboxes.min.js"></script> -->
<script type="text/javascript">
$(document).ready(function($)
{
$('#mydatatable tfoot th').each( function (index) {
//alert("in Tfoot");
console.log("tfoot th");
var title = $(this).text();
var notapplyFilteronColumn =[0]
if(notapplyFilteronColumn.indexOf(index) < 0 )
{
$(this).html( '<input type="text" id="txtName'+index+'" placeholder="Search '+title+'" data-index="'+index+'" />' );
}
} );
var table = $('#mydatatable').DataTable({
order:[[3,'desc']],
// processing: true,
pagingType:'full_numbers',
pageLength:20,
scrollY:500,
scrollX:true,
searchable: true,
// bFilter: false,
lengthMenu:[[5,10,25,50,-1],[5,10,25,50,"All"]],
select: {
style: 'multi'
},
columnDefs: [ {
orderable: false,
className: 'select-checkbox',
targets: 0,
}
],
select: {
style: 'multi',
selector: 'td:first-child'
},
search:
{
caseInsensitive: true,
smart: true
},
order: [[ 1, 'asc' ]],
initComplete: function () {
// Apply the search
console.log("Inside initcomplete");
this.api().columns().every( function (index) {
var that = this;
$( 'input', this.footer() ).on( 'keyup change clear', function () {
console.log("inside Keyup change");
console.log("index = "+index);
if ( that.search() !== this.value ) {
that
.search(this.value)
.draw();
}
} );
} );
} //initcomplete
}); //dt
});
</script>
</body>
</html>