Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82475

How individual column searching (text inputs) with cycle "for" in template Django ?

$
0
0

I need to create filters by field with "datatable" in django template, the fields I go through with a "for" cycle, but the javascript code does not work to traverse the different values ​​of the object ???

<div class="row">
    <div class="col-lg-12">
        <table id="tabla" class="table table-striped table-bordered" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th class="text-center">field_1</td>
                    <th class="text-center">field_3</td>
                    <th class="text-center">field_4</td>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th class="text-center">field_1</td>
                    <th class="text-center">field_3</td>
                    <th class="text-center">field_4</td>
                </tr>
            </tfoot>
            <tbody>
            {% for list in list_field %}
                <tr>
                    <td>{{ list.field_1}}</td>
                    <td>{{ list.field_2}}</td>
                    <td>{{ list.field_3}}</td>
                </tr>
            {% endfor %}
            </tbody>
        </table
    </div>
</div>

$(document).ready(function() { // Setup - add a text input to each footer cell $('#tabla tfoot th').each( function () { var title = $(this).text(); $(this).html( '<input type="text" placeholder="Search '+title+'" />' ); } ); // DataTable var table = $('#tabla').DataTable(); // 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(); } } ); } ); } );

Viewing all articles
Browse latest Browse all 82475

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>