1

i want add excel, copy , pdf , print buttons in the angular js . but im getting error while showing buttons in the data table. data table is working fine but when i added button code the datatable is not working error

Uncaught Error: [$injector:modulerr]

styles and js references

  <script src="~/angularjs/jquery.js"></script>
    <script src="~/angularjs/jquery.dataTables.js"></script>
    <script src="~/angularjs/angular.min.js"></script>
    <script src="~/angularjs/angular-datatables.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.2.2/css/buttons.dataTables.min.css">
<script src="https://cdn.datatables.net/buttons/1.2.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.colVis.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.flash.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.print.min.js"></script>

html

<div ng-app="MyApp" class="container">
                        <div ng-controller="homeCtrl">
                            <table id="entry-grid" datatable="" dt-options="dtOptions" dt-columns="dtColumns" class="table table-hover"></table>
                        </div>
                    </div>

code

var app = angular.module('MyApp', ['datatables']);
app.controller('homeCtrl', ['$scope', '$http', 'DTOptionsBuilder', 'DTColumnBuilder',
    function ($scope, $http, DTOptionsBuilder, DTColumnBuilder) {
        $scope.dtColumns = [
            DTColumnBuilder.newColumn("timestamp", "Time"),
            DTColumnBuilder.newColumn("dataFrame", "data Frame"),
            DTColumnBuilder.newColumn("fcnt", "fcnt"),
            DTColumnBuilder.newColumn("freq", "freq"),
            DTColumnBuilder.newColumn("rssi", "rssi")
        ]

        $scope.dtOptions = DTOptionsBuilder.newOptions()
            .withOption('ajax', {
            url: "/Manhole/GetManholeReadings",
            type: "POST"
            })
            .withButtons([
                'copy',
                'pdf',
                'excel'
            ])
        .withPaginationType('full_numbers')
        .withDisplayLength(10);

    }])
4

1 回答 1

0

您还需要包括在内datatables.buttons,即

var app = angular.module('MyApp', ['datatables', 'datatables.buttons']);

并将B标志包含在 中dom,即

$scope.dtOptions = DTOptionsBuilder.newOptions()
  ...
  .withOption('dom', 'Blfrtip')  //for a full featured datatable including buttons
于 2019-01-04T11:31:56.277 回答