Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
119 views
in Technique[技术] by (71.8m points)

javascript - Datatable table.columns() search Doesnt work, Why?

I am trying to search in a specific columns in datatable.. But I couldnt do it.. I can search outside of datatable for all columns but cant do it in 1.. I read otther questions and try to di it but couldnt do it..

Maybe I need to add a new library for that search ?

This works for me for ALL table search:

<input type="text id="urunara">


$('#urunara').on( 'keyup', function () {
    DataTable.search( this.value ).draw();
});

But this isnt worked for me just for 1 columns:

var table = $("#user_data").DataTable();

    <select id="sistemsearch">
<option value="PERGOLA">PERGOLA</option>
<option value="SKYFREE">SKYFREE</option>
</select>


$("#sistemsearch").on("change", function() {
  table
    .columns(5)
    .search(this.value)
    .draw();
});

What is wrong?

also all code:

<script type="text/javascript" language="javascript" >
$(document).ready(function(){
$('#add_button').click(function(){
$('#user_form')[0].reset();
$('.modal-title').text("ürün Ekle");
$('#action').val("Ekle");
$('#operation').val("Add");
$('#user_uploaded_image').html('');
});
var DataTable = $('#user_data').DataTable({
"language": 
{
"lengthMenu": "Sayfa Ba??na _MENU_ ürün G?ster",
"zeroRecords": "Arad???n?z Kriterlere uygun ürün Bulunamad?, ?zür Dileriz!",
"info": "",
"infoEmpty": "Hi? Bir Kay?t Uygun De?il",
"infoFiltered": "(_TOTAL_  ürün aras?ndan _MAX_ ürün filtrelendi)",
"search": "ürünler Aras?nda Ara",
"paginate": {
"previous": "?nceki ",
"next": "Sonraki "
}},
"processing":true,
"serverSide":true,
"order":[],
"ajax":{
url:"fetch.php",
type:"POST"
},
"columnDefs":[
{
"rowReorder": false,
"targets":[0],
"orderable":false,
},
],
"paging": true,
"searching": true,
"ordering": false,
"autoWidth": true,
"dom": '<"top"ilp<"clear">>rt<"bottom"iflp<"clear">>'
});

$('#urunara').on( 'keyup', function () {
    DataTable.search( this.value ).draw();
});


var table = $("#user_data").DataTable();

$("#sistemsearch").on("change", function() {
  table
    .columns(5)
    .search(this.value)
    .draw();
});

</script>
question from:https://stackoverflow.com/questions/66058570/datatable-table-columns-search-doesnt-work-why

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You probably have a typo in

.columns(5)
.search(this.value)

Could you please try with column(5).search(this.value) instead?

Source: https://datatables.net/reference/api/column().search()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...