Columns won't freeze when individual column filtering applied

Columns won't freeze when individual column filtering applied

kzkkzk Posts: 9Questions: 4Answers: 1

I have an html table where I need the header frozen, 2 left columns frozen, and show the option to filter on all other columns (not the 2 left columns). When I did fixed columns by itself it worked great.. but when I added the code to include drop down filtering on columns the fixed column option doesn't work. any idea how I can resolve this?? The header is frozen, the individual column filtering works (yay) but the 2 left columns are not frozen. code below:

<script>
        $(document).ready(function () {
            $('#primary').DataTable({
                initComplete: function () {
                    this.api().columns([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]).every(function () {
                        var column = this;
                        var select = $('<select><option value="">Show All</option></select>')
                            .appendTo($(column.header()))
                            .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) {
                            var val = $('<div/>').html(d).text();
                            select.append('<option value="' + val + '">' + val + '</option>');
                        });
                    });
                },
                paging: false,
                sort: false,
                scrollY: 500,
                scrollX: true,
                select: true,
                fixedColumns: {
                    leftColumns: 2
                },
                fixedHeader: {
                    header: true,
                },

            });
        });
    </script>

table:

<table id="1" class="table table-striped">
    @if (Model.1Function != null)
    {
        <thead>
            <tr>
                @foreach (DataColumn column in (Model.1Function as DataTable).Columns)
                {
                    <th>@column.ColumnName.ToUpper()</th>//header row
                }
            </tr>
        </thead>
        <tbody>
            @if ((Model.1Function as DataTable).Rows.Count > 0)
            {
                foreach (DataRow dr in (Model.1Function as DataTable).Rows)
                {
                    <tr>
                        @foreach (DataColumn column in (Model.1Function as DataTable).Columns)
                        {
                            <td style="max-width:200px; white-space:normal">
                                @dr[column].ToString()
                            </td>//write one row at a time.
                        }
                    </tr>
                }
            }
            else
            {
                var count = (Model.1Function as DataTable).Columns.Count;
                <tr>
                    <td colspan='@count' style="color:red;">
                        No Data Found.
                    </td>
                </tr>
            }
        </tbody>

    }
    else
    {
        <tr>
            <td style="color:red;">
                @(Model.1Function .HasErrors != false ? Model.1Function .HasErrors.ToString() : "")
            </td>
        </tr>
    }
</table>

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.