0

I want to use datatable in angularjs. I have written directives and data table initializing and displaying rows in table first time. When searching or filtering,it shows no data in table error message.

Directive code is

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

        }
    }
})

Template is,

<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>

Controller is,

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

enter image description here Why it happening ?

3
  • what module used for Data table ? or just jQuery Data table Commented Mar 5, 2015 at 9:31
  • yes..jquery.dataTables.min.js Commented Mar 5, 2015 at 9:33
  • thats weird, I faced similar problem, better use this angular Datatable l-lin.github.io/angular-datatables/#/withAjax Commented Mar 5, 2015 at 9:35

2 Answers 2

1

Instead of creating new directive, simply add datatable=" using this angular datatable module

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 Datatable and Download

Sign up to request clarification or add additional context in comments.

3 Comments

var invoiceApp = angular.module('invoiceApp', ['ngRoute','datatables']);when I am declaring datatables,I getting angular error.which is Error: [$injector:modulerr] .....
you downloaded that file and included ?
Yes, problem with file.Now datatable working fine for static table.But when I am trying to load data from controller via service,it shows same error.
1

Use "ng" inside your datatables="" directive.. Like this: datatables="ng" click here to see an example This solves the problem in my case as i am using ng repeat to show the data in the table

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.