我想在angularjs中使用数据表。我已经编写了指令和数据表,并在表中首次初始化和显示行。
搜索或过滤时,表错误消息中未显示任何数据。

指令代码是

"use strict";
invoiceApp.directive('itemTable', function () {
return {
        restrict: 'E',
        replace: true,
        templateUrl: 'app/components/item/item_table.html',
        link: function (scope, table) {
            table.dataTable();

        }
    }
})


模板是

<table my-table id="dt_basic" class="table table-bordered table-hover" width="100%">
<thead>
    <tr>
        <th class="text-center" width="10">
            <input type="checkbox" name="checkbox-inline" id="slt_all">
        </th>
        <th data-class="expand">Name</th>
        <th data-hide="phone">Description</th>
        <th data-hide="phone">Unit</th>
        <th>Rate</th>
    </tr>
</thead>
<tbody>
    <tr ng-repeat="item in items">
        <td class="text-center"><input type="checkbox" checked="checked" name="checkbox-inline"></td>
        <td>{{item.name}}</td>
        <td>{{item.description}}</td>
        <td>{{item.unit}}</td>
        <td>AED {{item.rate}}</td>
    </tr>


 

控制器是

    'use strict';
    invoiceApp.controller('itemController', ['$scope', 'ItemService', function ($scope, ItemService) {
$scope.items = //datas
        }]);



为什么会这样呢?

最佳答案

无需创建新指令,只需使用此角度数据表模块添加datatable="

HTML:

<table datatable="" class="row-border hover">
    <thead>
    <tr>
        <th>ID</th>
        <th>First name</th>
        <th>Last name</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>1</td>
        <td>Foo</td>
        <td>Bar</td>
    </tr>
    <tr>
        <td>123</td>
        <td>Someone</td>
        <td>Youknow</td>
    </tr>
    <tr>
        <td>987</td>
        <td>Iamout</td>
        <td>Ofinspiration</td>
    </tr>
    </tbody>
</table>


JS:

angular.module('showcase', ['datatables']);


More detail AngularJs DatatableDownload

关于javascript - 与angularJs的数据表显示没有数据错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28874284/

10-11 02:10
查看更多