2

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>
Pawan Kalyan
  • 583
  • 3
  • 11
  • 19
  • 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 http://angular-ui.github.io/ng-grid/ – Brocco Apr 10 '14 at 07:39
  • maybe help to you http://stackoverflow.com/questions/14242455/using-jquery-datatable-with-angularjs – daremachine Apr 21 '14 at 22:16

0 Answers0