Dropdown searching is not happing for individual columns

Dropdown searching is not happing for individual columns

SandeepMuralaSandeepMurala Posts: 48Questions: 13Answers: 0
edited March 2020 in Free community support

HI ,

I am using this reference for individual columns search:
https://datatables.net/examples/api/multi_filter_select.html
In that case they are using table data manually (hardcoded) but in my case data coming from server.php using ajax .
My data like this;

$('#example').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "server.php?min="+min+"&max="+max,
        initComplete: function () {
            this.api().columns().every( function () {
                var column = this;              
                var select = $('<select><option value=""></option></select>')
                    .appendTo( $(column.footer()).empty() )
                    .on( 'change', function () {
                        var val = $.fn.dataTable.util.escapeRegex(
                                 $(this).val()
                        );
 
                        column                  
                            .search( val ? '^'+val+'$' : '', true, false )
                            .draw();
                    } );
 
                column.data().unique().sort().each( function ( d, j ) {
                    select.append( '<option value="'+d+'">'+d+'</option>' )
                } );
            } );
        }
    } );
} );

HTML code:

<table id="example" class="display" style="width:100%">
        <thead>
            <tr>
                <th>Test1</th>
                <th>Test2</th>
                <th>Test3</th>
                <th>Tes4</th>
                  
        </thead>
    <tfoot>
            <tr>
        <th>Test1</th>
                <th>Test2</th>
                <th>Test3</th>
                <th>Test4</th>
            </tr>
        </tfoot>
          
        </tbody>
      
    </table>

My problem is when i select dropdown i am not getting search result ,i am getting like No matching records found
dropdown values coming properly ,but searching is not happing.
Could you please help me any one .i was setting from 2 days on this .

Thanks
Sandee

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    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

  • SandeepMuralaSandeepMurala Posts: 48Questions: 13Answers: 0
    edited March 2020

    hi @colin ,thanks for your valuable response ,i can give the test case but problem is my data comimg from database in server.php file ;
    in server.php file my code like this ;

    $table = 'test_table';
     
    // Table's primary key
    $primaryKey = 'id';
    $columns = array(
        array( 'db' => 'test1', 'dt' => 0 ),
        array( 'db' => 'test2', 'dt' => 1 ),
        array( 'db' => 'test3',  'dt' => 2 ),
        array( 'db' => 'test4',   'dt' => 3 )
    );
    $sql_details = array(
        'user' => 'root',
        'pass' => '',
        'db'   => 'Test_db',
        'host' => 'localhost'
    );
    require( 'ssp.class.php' );
    echo json_encode(
        SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns)
    );
    

    i have given my html and js code in above ,kinldy check once all are workinf fine only but search is not happing ,when i select paerticluar column value by the dropdown it not happing .
    kindly give me solution.

    Thanks
    Sandeep

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    There are a few threads on this, such as this one here, it would be worth following those.

    Colin

This discussion has been closed.