How to filter a certain column in a data table after a search button click

How to filter a certain column in a data table after a search button click

solasguitarrasolasguitarra Posts: 1Questions: 1Answers: 0

I have a data table which I use a search button instead of a key up function on,

var table2 =  $("#last2").DataTable({
                            initComplete : function() {
                                var input = $('.dataTables_filter input').unbind(),
                                    self = this.api(),
                                    $searchButton = $('<button>')
                                               .text('search')
                                               .click(function() {
                                                  self.search(input.val()).draw();
                                               }),
                                    $clearButton = $('<button>')
                                               .text('clear')
                                               .click(function() {
                                                  input.val('');
                                                  $searchButton.click();
                                               })
                                $('.dataTables_filter').append($searchButton, $clearButton);
                            },
                            "columnDefs": [ {
                                   "searchable": false,
                                   "orderable": false,
                                   "targets": 0
                               } ],
                               "order": [[ 1, 'asc' ]],
                                select:true,
                                "scrollX":false,
                                "scrollY": "55vh",
                                "scrollCollapse": true,
                                "paging":false,
                                "bFilter": true
                            });

And in my table there is an ID column which gives me the partIDs, I want to filter the shown data after I click the search button and filter the result if IDs are the same and want it to show only one of those rows that have the same ID, or show only one of each IDs, basically unique. For example I search for a 'BOLT', it shows me all the bolts with the same ID, I only want to see one of those with the same ID.

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Hi @solasguitarra ,

    If the other IDs match, then they will be returned - maybe a regex would help.

    If no joy, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.