1

This is a working script, but the dropdown option only displays the first 10 data and not all data in the table. What seems to be the problem here?

$(function() {
    $('#example').DataTable( {
        dom: "Bfrtip",
        ajax: {
            url: "account_type_table.php",
            type: "POST"
        },
        serverSide: true,
        columns: [
            { data: "seriesno" },
            { data: "accounttype" },
            { "data": "seriesno", "name": " ", "autoWidth": true, "render": function (data, type, full, meta) {
                return "<button class='btn btn-success btn-sm btn-flat edit' data-id='"+full.seriesno+"'><i class='fa fa-edit'></i> Edit</button> <button class='btn btn-danger btn-sm btn-flat delete' data-id='"+full.seriesno+"'><i class='fa fa-trash'></i> Delete</button>";}
                        }
        ],
        initComplete: function () {
        this.api().columns([0,1]).every( function () {
            var column = this;
            var select = $('<select class="form-control"><option value=""></option></select>')
                .appendTo( $(column.footer()).empty() )
                .on( 'change', function () {
                    var val = $(this).val();
                    column.search( this.value ).draw();
                } );

            console.log(column.data().unique());

            column.data().unique().sort().each( function ( d, j ) {
                select.append( '<option value="'+d+'">'+d+'</option>' )
            } );
        } );
    },
        select: false,
        buttons: [],
    } );
} );
5
  • With server side processing, your table is populated with certain portion of your data, the rest is retrieved as you move through pages or change sorting/filtering. That's why column.data().unique() returns only (currently loaded) part of your data. If you need the rest, you must pass all available option values from your backed, instead. Commented Aug 10, 2019 at 5:27
  • Possible duplicate of Dropdown selection using Server Side dataTable | PHP, SQLSRV Commented Aug 10, 2019 at 5:30
  • @YevgenGorbunkov can you provide a guide on how to do that? I'm completely confused on how to approach it. I was the one who posted your second comment :) Commented Aug 10, 2019 at 5:56
  • My second comment simply means that I flagged your another question as a duplicate of this one. Posting identical questions over and over again doesn't increase your chances to get the answer at SO. Commented Aug 11, 2019 at 5:32
  • As for your request for guidance, it's too much specific to your environment and is mostly SQL/PHP job. So, if you don't know how to approach that, start asking smaller questions, e.g. 'How do I query distinct values of each column from DB?', then 'How do I wrap array of distinct DB values into AJAX-response', etc Commented Aug 11, 2019 at 5:35

0

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.