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>
2
  • 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 Commented Apr 10, 2014 at 7:39
  • maybe help to you stackoverflow.com/questions/14242455/… Commented Apr 21, 2014 at 22:16

0

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.