Filtering columns with dropdown

Filtering columns with dropdown

sjw01sjw01 Posts: 67Questions: 36Answers: 1
edited September 2019 in Free community support

I have created a dropdown filter on columns using the guide here: https://datatables.net/examples/api/multi_filter_select.html

Problem is, as you can see - the filter is broad match (e.g. Service returns Ford Service) not exact match (Column: Dept)
http://live.datatables.net/memajidi/1/edit?js,output

Is it possible to make the search filter exact match?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    Hi @sjw01 ,

    It just needs to be a regex,

                    .search('^' + $(this).val() + '$', true, false )
    

    See here,

    Cheers,

    Colin

  • suganya_gsuganya_g Posts: 1Questions: 0Answers: 0
    edited March 2021
     <script>
                
                var KTDatatableRemoteAjaxDemo = function () {
    
                var demo = function () {
                    var t;
                    t = $('.kt-datatable').KTDatatable({
                        data: {
                            type: 'remote', 
                            source: {
                                read: {
                                    url: 'engage.php?eng=all',
                                    headers: {
                                        'x-my-custom-header': 'some value', 'x-test-header': 'the value'
                                    },
                                    map: function (raw) {
                                        var dataSet = raw; 
                                        if (typeof raw.data !== 'undefined') { 
                                            dataSet = raw.data; 
                                        } 
                                        $('.blockUI.blockMsg.blockElement.alllist').remove(); 
                                        return dataSet;
                                    },
                                },
                            }, 
                            pageSize: 10, 
                            serverPaging: true, 
                            serverFiltering: true, 
                            serverSorting: true,
                        },
                        layout: {
                            scroll: true,
                            //height:550,
                            footer: false,
                        },
                        sortable: true,
                        pagination: true,
                        search: {
                            input: $('#generalSearch'),
                            // input: $('#rm_filter'),
                        },
          
                        rows: {
                            autoHide: false,
                        },
                        columns: [
                        
                            {
                        field: "reporting-to-name",
                        title: " Reporting Name",
                        sortable: true,
                    },
                
                    {
                        field: "e-email",
                        title: "Email",
                        sortable: true,
                    }
                   
                        ],
        
    
                    
                    });
                    $('#rm_filter').selectpicker();
    
                     $('#rm_filter').on("change", function(e) {
                     t.search($(this).val(), "rm_filter");  
                     });
    
                
    
            
    
                };
                return {
                    init: function () {
                        demo();
                    },
                };
                }();
                jQuery(document).ready(function () { KTDatatableRemoteAjaxDemo.init(); });   
                
     </script>
    

    ......This is my code i have filter with proper option value but all the data not filter in datatable ...only one field has applying filter condition ...select option filter data is dynamic in php mysql...Is there any solution ?

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

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

    KTDatatable isn't anything to do with us, I'd suggest posting on StackOverflow or on their site : https://keenthemes.com/metronic/?page=docs&section=html-components-datatable

    Colin

This discussion has been closed.