1

I need to add a dropdown filter option in the database table, which displays records in the table based on the value selected. I checked latest documentation of DataTable and tried following :

$('#checkin-checkout-record-table').dataTable({
   /* "dom": '<"toolbar">C<"clear">lfrtip<"clear">T',
    tableTools: {
        "sSwfPath": app.baseurl("/gbdportal/assets/js/libs/TableTools-2.2.4/swf/copy_csv_xls_pdf.swf"),
        "aButtons": [{
            "sExtends": "xls",
            "oSelectorOpts": { filter: 'applied', order: 'current'  }

        }]
    },*/
    "bPaginate": true,
    "bLengthChange": true,
    "bFilter": true,
    "bSort": true,
    "bInfo": true,
    // "order": [[0, 'asc'], [4, 'asc']],
    "aLengthMenu": [50, 100],
    "bAutoWidth": false,

    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>' )
            } );
        } );
    }
});

But filter dropdowns are not displayed. I think it might be due to version incompatibility. I am using 1.10.0-dev version.

1
  • maybe you can add a jsFiddle so we can help you better Commented Oct 11, 2017 at 8:03

1 Answer 1

1

Your mistake is that you are trying to use Datatables 1.10.0 version with the legacy Databales

This can be seen from your Datatables initialisation code :

$('#checkin-checkout-record-table').dataTable({....

where the correct using 1.10.0+ would be (MIND THE CAPS):

$('#checkin-checkout-record-table').DataTable({

You can either use legacy dataTables or new DataTables to do what you want but always with the code matching your preferred version.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.