AngularJS Datatable:响应式不起作用

2024-04-28

我在用着角度数据表 http://l-lin.github.io/angular-datatables/archives/ with 响应表 http://l-lin.github.io/angular-datatables/archives/#!/withResponsive,但不起作用:表格看起来没有响应选项。

Module:

(function ()
{
    'use strict';

    angular
        .module('app.myapp',['datatables'])
        .config(config);

    function config($stateProvider)
    {
        $stateProvider.state('app.myapp', {
            url      : '/',
            views    : {
                'content@app': {
                    templateUrl: 'app/main/myapp.html',
                    controller : 'MyController as vm'
                }
            }
        });
    }
})();

控制器:

(function ()
{
'use strict';

angular
    .module('app.myapp')
    .controller('MyController', MyController);

function MyController(DTColumnBuilder, DTOptionsBuilder)
{
    var vm = this;

    vm.dtOptions = DTOptionsBuilder.newOptions()
        .withOption('ajax', {
            url: '/rest/getfoo', 
            type: 'POST',
            dataSrc: "data",
        })
        .withOption('processing', true)
        .withOption('serverSide', true)
        .withOption('responsive', true)
        .withPaginationType('full_numbers')
        .withDisplayLength(20);

    vm.dtColumns = [];
    }
})();

模板:

<table datatable class="dataTable row-border hover responsive nowrap"  
    dt-options="vm.dtOptions" 
    dt-columns="vm.dtColumns" 
    width="100%" 
    cellspacing="0">
</table>

加载数据表响应资源:

<link rel="stylesheet" href="../bower_components/datatables/media/css/jquery.dataTables.css">
<script src="../bower_components/datatables-responsive/js/dataTables.responsive.js"></script>

为什么我的数据表没有响应?


您必须包含响应式源代码:

datatables.net-responsive
datatables.net-responsive-dt

最新版本是2.1.1,使用bower你可以这样做:

bower install datatables.net-responsive#2.1.1 --save
bower install datatables.net-responsive-dt#2.1.1 --save

Now .withOption('responsive', true)应该管用。与许多其他插件不同,它不需要依赖即可发挥作用。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

AngularJS Datatable:响应式不起作用 的相关文章

随机推荐