Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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

share|improve this question
    
Btw, did you checked angular-table? – Atropo Feb 12 '14 at 11:05
    
@Atropo thanks for that, although I must have filtering box and pagination – Tjorriemorrie Feb 13 '14 at 7:03

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: http://stackoverflow.com/a/16096071/2383201

share|improve this answer
    
Yes, but ng-grid does not yet support 1.2. Till then... – Tjorriemorrie Feb 13 '14 at 6:59
    
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 – Tjorriemorrie Feb 13 '14 at 7:02

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.