Why is the column search not working after i implemented german.json - File ?

Why is the column search not working after i implemented german.json - File ?

CarrearCarrear Posts: 3Questions: 1Answers: 0

I tested it forwards and backwards ... when german.json is included for translation, the column-specific search always returns 'no results'.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin
    Answer ✓

    You might need to move the column filter initialisation into initComplete. However, without a test case I can't be certain.

    Allan

  • CarrearCarrear Posts: 3Questions: 1Answers: 0

    Would it be enough to show you the js code for initialization?

        <script type="text/javascript">
            $(document).ready(function() {
                // Setup - add a text input to each footer cell
                $('#krisendatenbank tfoot th').each( function () {
                    var title = $(this).text();
                    $(this).html( '<input type="text" placeholder="Suche '+title+'" />' );
                } );
                
                
                // DataTable
                var table = $('#krisendatenbank').DataTable({
                    responsive: true,
                    language: {
                        "url": "<we:url type="document" id="16107" />"
                    },
                    initComplete: function () {
                        var r = $('#krisendatenbank tfoot tr');
                        r.find('th').each(function(){
                            $(this).css('padding', 8);
                        });
                        $('#krisendatenbank thead').append(r);
                        $('#search_0').css('text-align', 'center');
                    }
                    });
                
                // 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>
    
  • CarrearCarrear Posts: 3Questions: 1Answers: 0

    Your solution is easy and great :D in other word: It works. Thank you.

        <script type="text/javascript">
            $(document).ready(function() {
                // Setup - add a text input to each footer cell
                $('#krisendatenbank tfoot th').each( function () {
                    var title = $(this).text();
                    $(this).html( '<input type="text" placeholder="Suche '+title+'" />' );
                });
                
                
                // DataTable
                var table = $('#krisendatenbank').DataTable({
                    language: {
                        "url": "<we:url type="document" id="16107" />"
                    },
                    responsive: false,
                    initComplete: function () {
                        // 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();
                                }
                            });
                        });
                        var r = $('#krisendatenbank tfoot tr');
                        r.find('th').each(function(){
                            $(this).css('padding', 5);
                        });
                        $('#krisendatenbank thead').append(r);
                        $('#search_0').css('text-align', 'center');
                    }
                    });
                
            });
        </script>
    
This discussion has been closed.