0

I'm using angular-datatables but when I'm using ng-repeat, the functions of datatables doesn't work (sort, search, count, etc)

HTML:

<table  datatable=""  class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
    <tr>
        <th><input type="checkbox" id="checkall" /></th>
        <th>Navn</th>
        <th>Projekt</th>
        <th>Timer</th>
        <th>Uge</th>
        <th>Edit</th>
    </tr>
    </thead>

    <tbody ng-repeat="timesheet in timesheets">
    <tr>
        <td><input type="checkbox" class="checkthis" /></td>
        <td>{{timesheet.user}}</td>
        <td>{{timesheet.projectid}}</td>
        <td>  <standard-time-no-meridian etime='timesheet.TotalTime'></standard-time-no-meridian></td>
        <td>{{timesheet.week}}</td>
        <td><p data-placement="top" data-toggle="tooltip" title="Edit"><button class="btn btn-primary btn-xs" data-title="Edit" data-toggle="modal" data-target="#edit" ><span class="glyphicon glyphicon-pencil"></span></button></p></td>
    </tr>
    </tbody>

 </table>

JavaScript:

  .controller('TimesheetMainCtrl', function ($rootScope, $scope, $timeout) {

   dpd.timesheetold.get(function (result, err) {

        if (err) return console.log(err);
       $timeout(function() {
           $scope.timesheets = result;


       })
    })

});

I tried adding ng to datatable="" but this just give me an console error

TypeError: Cannot read property 'serverSide' of undefined at Object.f [as fromOptions] (angular-datatables.min.js:6)

davidkonrad
  • 83,997
  • 17
  • 205
  • 265
Thomas
  • 123
  • 1
  • 1
  • 12
  • I think you should have `ng-repeat="timesheet in timesheets"` on `tr` element, not `tbody`. Also set `datatable="ng"`, see [angular way](http://l-lin.github.io/angular-datatables/#/angularWay) for more details. – Gyrocode.com Oct 22 '15 at 20:17
  • did move it to tr tag, and set datatable="ng" but this just gives me the console error – Thomas Oct 22 '15 at 20:35

2 Answers2

1

seams to be an error in angular datatables https://github.com/l-lin/angular-datatables/issues/439

will be fixed in 0.51 until that it works running an older version

Thomas
  • 123
  • 1
  • 1
  • 12
0

Been dealing with this problem for a while and the issue actually was that if I refreshed the page on the state that contained the datatable, it would break.

It would work if you navigate to it, from another state. Thus, I made a workaround by redirecting to another state on refreshing the page.

Peter Buju
  • 177
  • 1
  • 8