Javascript jquery DataTables-列筛选器在选择筛选器之前不会对齐

Javascript jquery DataTables-列筛选器在选择筛选器之前不会对齐,javascript,jquery,html,razor,datatables,Javascript,Jquery,Html,Razor,Datatables,我正在尝试解决以下问题。我使用jQueryDataTables进行水平滚动和列下拉筛选,出于某种原因,我的表在选择要筛选的列之前不会对齐,然后它就完美地对齐了。是否有任何方法可以立即执行此操作,即当页面加载时?谢谢你的帮助 我的JS: @section Scripts{ <script type="text/javascript" src="https://cdn.datatables.net/v/bs/dt-1.10.12/datatables.min.js"></scrip

我正在尝试解决以下问题。我使用jQueryDataTables进行水平滚动和列下拉筛选,出于某种原因,我的表在选择要筛选的列之前不会对齐,然后它就完美地对齐了。是否有任何方法可以立即执行此操作,即当页面加载时?谢谢你的帮助

我的JS:

@section Scripts{
<script type="text/javascript" src="https://cdn.datatables.net/v/bs/dt-1.10.12/datatables.min.js"></script>
<script>
    $(document)
        .ready(function() {
            $('#callableIncome_table')
                .DataTable({
                    scrollX: true,
                    initComplete: function() {
                        var api = this.api();

                        api.columns()
                            .indexes()
                            .flatten()
                            .each(function(i) {
                                var column = api.column(i);
                                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>');
                                    });
                            });
                    }
                });
        });
</script>
@节脚本{
$(文件)
.ready(函数(){
$(“#可赎回收入表”)
.数据表({
是的,
initComplete:function(){
var api=this.api();
api.columns()
.index()
.flatte()
.每项功能(i){
var column=api.column(i);
变量选择=$(“”)
.appendTo($(column.footer()).empty())
.on('变更'),
函数(){
var val=$.fn.dataTable.util.escapeRegex(
$(this.val()
);
柱
.search(val?“^”+val+“$”:“”,true,false)
.draw();
});
column.data()
.unique()
.sort()
.每个(功能(d,j){
select.append(“”+d+“”);
});
});
}
});
});
} @剖面样式{ }

我的html:

<div class="container" style="margin-top: 2%" >
<table id="callableIncome_table" class="table table-striped table-bordered" style="white-space: nowrap">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Underlyer)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.PayoutCurrency)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.AutoCallLevel)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Barrier)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.CouponBarrier)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.AutoCallablePattern)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Frequency)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Term)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Fee)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.UpsideParticipation)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Coupon)
            </th>
            <th>
                @Html.DisplayNameFor(model =>model.AsOfDate)
            </th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Underlyer)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.PayoutCurrency)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.AutoCallLevel)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Barrier)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.CouponBarrier)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.AutoCallablePattern)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Frequency)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Term)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Fee)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.UpsideParticipation)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Coupon)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.AsOfDate)
            </th>
        </tr>
    </tfoot>
    <tbody>
        @foreach (CallableIncomeViewModel callableIncomeVM in Model)
{
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => callableIncomeVM.Underlyer)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => callableIncomeVM.PayoutCurrency)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => callableIncomeVM.AutoCallLevel)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => callableIncomeVM.Barrier)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => callableIncomeVM.CouponBarrier)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => callableIncomeVM.AutoCallablePattern)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => callableIncomeVM.Frequency)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => callableIncomeVM.Term)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => callableIncomeVM.Fee)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => callableIncomeVM.UpsideParticipation)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => callableIncomeVM.Coupon)
                </td>
                <td>
                    @Html.DisplayFor(modelItem =>callableIncomeVM.AsOfDate)
                </td>
            </tr>
}
    </tbody>
</table>

@DisplayNameFor(model=>model.underlayer)
@DisplayNameFor(model=>model.PayoutCurrency)
@DisplayNameFor(model=>model.AutoCallLevel)
@DisplayNameFor(model=>model.Barrier)
@DisplayNameFor(model=>model.CouponBarrier)
@DisplayNameFor(model=>model.AutoCallablePattern)
@DisplayNameFor(model=>model.Frequency)
@DisplayNameFor(model=>model.Term)
@DisplayNameFor(model=>model.Fee)
@DisplayNameFor(model=>model.UpsideParticipation)
@DisplayNameFor(model=>model.优惠券)
@DisplayNameFor(model=>model.AsOfDate)
@DisplayNameFor(model=>model.underlayer)
@DisplayNameFor(model=>model.PayoutCurrency)
@DisplayNameFor(model=>model.AutoCallLevel)
@DisplayNameFor(model=>model.Barrier)
@DisplayNameFor(model=>model.CouponBarrier)
@DisplayNameFor(model=>model.AutoCallablePattern)
@DisplayNameFor(model=>model.Frequency)
@DisplayNameFor(model=>model.Term)
@DisplayNameFor(model=>model.Fee)
@DisplayNameFor(model=>model.UpsideParticipation)
@DisplayNameFor(model=>model.优惠券)
@DisplayNameFor(model=>model.AsOfDate)
@foreach(模型中的CallableIncomeViewModel callableIncomeVM)
{
@DisplayFor(modelItem=>callableIncomeVM.underlayer)
@DisplayFor(modelItem=>callableIncomeVM.PayoutCurrency)
@DisplayFor(modelItem=>callableIncomeVM.AutoCallLevel)
@DisplayFor(modelItem=>callableIncomeVM.Barrier)
@DisplayFor(modelItem=>callableIncomeVM.CouponBarrier)
@DisplayFor(modelItem=>callableIncomeVM.AutoCallablePattern)
@DisplayFor(modelItem=>callableIncomeVM.Frequency)
@DisplayFor(modelItem=>callableIncomeVM.Term)
@DisplayFor(modeleItem=>callableIncomeVM.Fee)
@DisplayFor(modelItem=>callableIncomeVM.UpsideParticipation)
@DisplayFor(modelItem=>callableIncomeVM.优惠券)
@DisplayFor(modelItem=>callableIncomeVM.AsOfDate)
}

我的CSS:

@section Styles{
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs/dt-1.10.12/datatables.min.css" />}
@节样式{
}
如您所见,表中没有太多配置。我只是在DataTables站点上进行了演练

单击过滤器之前:

单击过滤器后: