How to have Custom Drop Down only in Some Datable Heards

How to have Custom Drop Down only in Some Datable Heards

AshutoshDAshutoshD Posts: 2Questions: 1Answers: 0

**https://datatables.net/examples/api/multi_filter_select.html**:

I am using code from above mentioned link for creating data table and I want for the First Column there shouldn't be the drop down. How it can be customized. Can some one please help on this.

Answers

  • AshutoshDAshutoshD Posts: 2Questions: 1Answers: 0
    edited March 2023

    URL is as following - https://datatables.net/examples/api/multi_filter_select.html

    In the above link ** is added.

    and below is the code which I am using.

    $(document).ready(function () {
        $('#example').DataTable({
            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>');
                            });
                    });
            },
        });
    });
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited March 2023

    Change this.api().columns() to select only the columns that you want to add a filter to (see columns() for details). For example:

    this.api().columns('.dropdown-search')
    

    to select all columns with that class.

    In future, please link to a test case showing the issue, per the forum rules.

    Thanks,
    Allan

Sign In or Register to comment.