Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I am using angularjs and populating data in a table using datatable directive. I was able to dispay the data. Now the requirement is add a click event to every row and on click i need to get the row data. How do I add the event listener to dynamically creating rows of data as I haven't worked with directives till now.Unable to find a way.gone through angularjs docs but couldn't find a solution

My directive is

angular.module('SampleApp.directives')
    .directive('datatable',
        function() {
            return {
                restrict: 'A',
                scope : {
                    tableData : '='
                },
                link: function (scope, element, attrs, controller) {
                    var dataTable = element.dataTable();
                    dataTable.fnAddData(scope.tableData);
                }
            }
        }
    );

The html is

                                    <div style="margin:10px">
                                    <table datatable table-data="organizations">
                                            <thead>
                                            <tr>
                                                <td>Organization Name</td>
                                                <td>Admin</td>
                                                <td>Admin Email</td>
                                                <td>Organization Type</td>
                                            </tr>
                                            </thead>

                                        </table>

                                    </div>
share|improve this question
    
2 things: consider using ng-grid instead of dataTable as it is a native angular table/grid solution (no jQuery). and to find the row elements, you'll have to roll jQuery style... after dataTable setup bind your clicks... element.find('tr').bind('click', function(){/*handle click*/}); And a link to ng-grid angular-ui.github.io/ng-grid – Brocco Apr 10 '14 at 7:39
    
maybe help to you stackoverflow.com/questions/14242455/… – daremachine Apr 21 '14 at 22:16

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.