Research in single columns doesn't work

Research in single columns doesn't work

fibofibo Posts: 2Questions: 1Answers: 0

I'm new in javascript programming. I'm trying to set-up the plug-in to search in single columns.
I've this script
```

$(document).ready(function() { // DataTable var table = $('#opTable').DataTable({ "language": { "url": "http://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Italian.json" }, "columnDefs": [ { "searchable": true, "orderable": true, "targets": [ 0 ], "orderData": [ 0, 1 ] }, { targets: [ 1 ], orderData: [ 1, 0 ] }, { targets: [ 4 ], orderData: [ 4, 0 ] }], }); // Setup - add a text input to each footer cell $('#opTable tfoot th').each( function () { var title = $('#opTable tfoot th').eq( $(this).index() ).text(); $(this).html( '' ); } ); // Apply the search table.columns().every( function () { var that = this; $( 'input', this.footer() ).on( 'keyup change', function () { if ( that.search() !== this.value ) { that .search( this.value ) .draw(); } } ); } ); } );
Applied to this HTML

``` <table class="tableDati" id="opTable">
         <thead>
         <tr>
        <th class="text-center">Data</th>
        <th class="text-center">Cod. Art.</th>
        <th class="text-center">Marca</th>
        <th class="text-center">Col.</th>
        <th class="text-center">N°</th>
         </tr>
    </thead>
    <tfoot>
        <tr>
            <th class="text-center">Data</th>
        <th class="text-center">Cod. Art.</th>
        <th class="text-center">Marca</th>
        <th class="text-center">Col.</th>
        <th class="text-center">N°</th>
        </tr>
    </tfoot>
    <tbody>
        <tr class="dat">
        <td class="text-center">11-04-2016</td>
        <td class="text-center">XYZ</td>
        <td class="text-center">Brand 1</td>
        <td class="text-center">Black</td>
        <td class="text-center">37</td>
       </tr>
       <tr class="dat">
        <td class="text-center">11-04-2016</td>
        <td class="text-center">XYF</td>
        <td class="text-center">Brand 2</td>
        <td class="text-center">Red</td>
        <td class="text-center">42</td>
        </tr>
    </tbody>
</table>

When I try to search in the single columns it gives as result: "No matching records found" also if the data are present in the columns.

Answers

  • fibofibo Posts: 2Questions: 1Answers: 0

    I'm afraid. This is my javascript code

    <script type="text/javascript">
            $(document).ready(function() {
                
                // DataTable
                var table = $('#opTable').DataTable({
                    "language": {
                        "url": "http://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Italian.json"
                    },
                    "columnDefs": [ {
                        "searchable": true,
                        "orderable": true,
                        "targets": [ 0 ],
                                "orderData": [ 0, 1 ]
                            }, {
                            targets: [ 1 ],
                            orderData: [ 1, 0 ]
                        }, {
                            targets: [ 4 ],
                            orderData: [ 4, 0 ]
                     }],
                });
                 
                // Setup - add a text input to each footer cell
                $('#opTable tfoot th').each( function () {
                    var title = $('#opTable tfoot th').eq( $(this).index() ).text();
                    $(this).html( '<input type="text" placeholder="Cerca '+title+'" />' );
                } );
             
                // Apply the search
                table.columns().every( function () {
                    var that = this;
             
                    $( 'input', this.footer() ).on( 'keyup change', function () {
                        if ( that.search() !== this.value ) {
                            that
                                .search( this.value )
                                .draw();
                        }
                    } );
                } );
            } );
       </script>
    
    
This discussion has been closed.