2

My html:

<table data-table ng-show="bookings">
    <thead>
        <tr>
            <th>Name</th>
            <th>Surname</th>
            <th>ID number</th>
            <th>Email</th>
            <th>Cellphone</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="booking in bookings | orderBy:['student.firstname', 'student.surname']">
            <td>{{ booking.student.firstname }}</td>
            <td>{{ booking.student.surname }}</td>
            <td>{{ booking.student.id_number }}</td>
            <td>{{ booking.student.email }}</td>
            <td>{{ booking.student.cellphone }}</td>
        </tr>
    </tbody>
</table>

My directive:

.directive('dataTable', function() {
        return {
            restrict: 'A',
            replace: false,
            transclude: true,
            link: function (scope, el, attrs) {
                console.info('dataTable', el);
                $(el).dataTable();
            }
        }
    })

I don't get any error, but nothing is displayed (I cannot now know what the el is). I wish to use it where the info is transcluded, and then the 'zero configuration' of dataTable are used. I thought this would be simple, alas, directives :(

2
  • Btw, did you checked angular-table? Commented Feb 12, 2014 at 11:05
  • @Atropo thanks for that, although I must have filtering box and pagination Commented Feb 13, 2014 at 7:03

3 Answers 3

0

Have you had a look at ng-grid? It's a native implementation that provides pagination / sorting etc.

But if you must use DataTables, have a look at this answer, I used the solution from here recently and it worked well: https://stackoverflow.com/a/16096071/2383201

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

1 Comment

I have seen that example. It's not really what I'm hoping to do. It has too much config which can be done via transclusion
0

You can't use data as a prefix for the attribute. Changing it to anything else, e.g. myTable (usage: my-table) will let the directive pick it up.

However, it can't seem to resolve the columns now, which means the only solution is the link given by @Skinty

Comments

0

You can also check the angular-datatables - Datables using angular directives project. It has a lot of examples on how to use angular directives with datatables.

I know this question is a bit old now but but I though it may help people who end up here searching for the same question.

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.