Unable to make searchBuilder work

Unable to make searchBuilder work

fsweb2011fsweb2011 Posts: 3Questions: 2Answers: 0
edited March 2023 in Free community support

Hi there
I have created a searcheable table with DataTables.
I have 6 columns but the search textbox I only want it to apply to columns 1 and 3 (0 and 2?)
All works fine, however I cannot make it just search/filter on columns 0 and 2

Everything works fine....except the search, which uses ALL columns, not just column 0 and 2 which is what I need to filter on.

For the data I am using an array.

So in the example below, if I type NEW YORK, I want only the first row to display, however it is displaying also the last 2, because NEW YORK is shown on column 5

I hope you can help me with this.
Sorry, I don't have access to a public place I can put the HTML page below.

Thank you

This is an extract of the code (only some data in array is shown):

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
<meta charset=utf-8 />
<title>INTERMODAL</title>
</head>
<BODY>
<div class='demo-html' style=width:80%>
<table id='example' class="display" width="100%"></table>
</div>

<script>
var ArraySet = [
['NEW YORK', '(NY)', 'US-10001', '500', 'NEW YORK', '', 'USD', '1110', '1110' , '1110', '0'], 
['SPRINGFIELD', '(OH)', 'US-45001', '594', 'CHICAGO', '', 'USD', '1319', '1319' , '1319', '0'], 
['CAMDEN', '(NJ)', 'US-10020', '600', 'NEW YORK', '', 'EUR', '1332', '1332' , '1332', '0'], 
['NEWARK', '(NJ)', 'US-10002', '730', 'NEW YORK', '', 'EUR', '1621', '1621' , '1621', '0'], 
];

$(document).ready(function () {
$('#example').DataTable({
'pageLength': 20, 
searchBuilder: {columns:[0,2]}, searchBuilderType: 'array', 
dom: 'Qlfrtip', 

data: ArraySet,
'order': [[ 1, 'asc' ], [ 7, 'asc' ]], 
columns: [
    { title: 'LOCATION' },
    { title: 'PROVINCE' },
    { title: 'ZIPCODE' },
    { title: 'KMS' },
    { title: 'PORT' },
    { title: 'MAIN' },
    { title: 'CUR' },
    { title: 'PRICE1' },
    { title: 'PRICE2' },
    { title: 'PRICE3' },
    { title: 'TOLL' },
 ],
'bAutoWidth': false, 
'columnDefs': [{'width':'25%', 'targets':[0] } , { 'width':'100px','targets':[1] } , {'width':'25%','targets': [2]},
               {'width':'50px' , 'targets':[3,6] } , { 'width':'100px','targets':[4,5] } , {'width':'65px','targets': [7,8,9,10]},
], 
 });
});
</script>
</body>
</html>

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Are you referring to the global search here - not specifically the search builder inputs? If so, which columns are considered by the standard search box are controlled by columns.searchable. Add searchable: false to the column objects you don't want to be searchable.

    Allan

  • fsweb2011fsweb2011 Posts: 3Questions: 2Answers: 0

    Wow, that's so embarrasing.
    I didn't even notice the searchable:true/false thing existed.
    Yes, that's what I was looking for.
    I searched for hours in the internet and all results were related to 'SearchBuilder'...
    Anyway, thank you so much for your help! You are a livesaver!

Sign In or Register to comment.