jQuery数据表宽度保持重置

时间:2016-12-19 22:32:48

标签: javascript jquery html angularjs datatables

我正在使用jquery Datatables向我的HTML表添加功能。我想将宽度设置为固定的%值。它可以工作,但每当我更改“显示x条目”下拉列表时,它会更改要在更改上显示的条目数,宽度将重置。如何停止此重置?

编辑:我认为当某些td元素非常大(300多个字符)时会发生这种情况。不知道如何解决这个问题

Html(使用angularjs框架,虽然这不重要):

    <table ng-if="itms && itms.length > 0" id="my-table" class="table table-striped" cellspacing="0">
    <thead>
        <tr>
            <th>c1</th>
            <th>c2</th>
            <th>c3</th>
            <th>c4</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>c1</th>
            <th>c2</th>
            <th>c3</th>
            <th>c4</th>
        </tr>
    </tfoot>
    <tbody>
        <tr ng-repeat="itm in itms track by $index" repeat-done>
            <td>{{itm.c1}}</td>
            <td>{{itm.c2}}</td>
            <td>{{itm.c3}}</td>
            <td>{{itm.c4}}</td>
        </tr>
    </tbody>
</table>

使用Javascript:

    $('#my-table').DataTable({
    "autoWidth": false,
    "columns": [
        {"width": "20%"},
        {"width": "5%"},
        {"width": "25%"},
        {"width": "50%"}
    ]
});

指令js

angular.module('myApp')
.directive('repeatDone', function($timeout) {
        return function(scope, element, attrs) {
        if (scope.$last) {
            $timeout(callback1);
        }
}
});
function callback1(){
    $('#my-table').DataTable({
    "autoWidth": false,
    "columns": [
        {"width": "20%"},
        {"width": "5%"},
        {"width": "25%"},
        {"width": "50%"}
    ]
});

0 个答案:

没有答案