Search code examples
angularjsdraggabletabular

How to recognize a cell of table, which has been clicked?


I am trying to make something like this on following picture.

enter image description here

I want to make a table, which looks like a calendar. Also I want make cells clickable and I want to know, which cell was clicked. Probably a HTML5 attribute data-* will be useful for it. It would be best if it could be "draggable", I mean if it would be possible to select more cells by drag of mouse.


Solution

  • You should be able to pass your model object or the item in the collection you are looping into your ng-click event method.

    Let's say you loop through a collection to render the cells

    <div ng-repeat="day in calendarDays">
      <a href="#" ng-click="dayClicked(day)">
         Show some markup here as needed
      </a>
    </div>
    

    Assuming calendarDays is an array / collection in your $scope and dayClicked is a method in your $scope which accepts a data structure which represents a day item.