0

I want to get the index of the td from the table which will be dynamic in number of column and rows. So I can't put ng-click on each td.

I get that using jquery like this ...

            <table border="1">
              <tr>
                <td>0</td>
                <td>1</td>
                <td>2</td>
                <td>3</td>
              </tr>
              <tr>
                <td>0</td>
                <td>1</td>
                <td>2</td>
                <td>3</td>
              </tr>
              <tr>
                <td>0</td>
                <td>1</td>
                <td>2</td>
                <td>3</td>
              </tr> 
            </table>
       <script>
            $("table tr").on("click", "td", function(){
                var col = this.cellIndex;
                //alert(col);
                $('table tr').find('td:eq('+col+'),th:eq('+col+')').remove();
            });
       </script>

So how to get that in my controller

            app.controller('MyCtrl1', function($scope){


            });

I get a dynamic table from where I need only few column. The $scope i will ng-repeat in the table, I want to edit that dynamical and post that data to database.

1
  • if you are applying ng-repeat over table then add you can find the column by using the $index. on td you can write data-ng-click=someMethod($index); Commented Apr 2, 2014 at 8:32

1 Answer 1

1

You can place a single ng-click directive on your table and pass the '$event' property as an argument to the called function:

<table ng-click="tableClicked($event)">
    <!-- Rest of the table contents -->
</table>

In your controller, you can then define the function to accept the event parameter:

$scope.tableClicked = function (event) {
    //event has all the details of the click event
};
Sign up to request clarification or add additional context in comments.

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.