Skip to content

Instantly share code, notes, and snippets.

@lordfriend
Created April 28, 2015 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lordfriend/4e8fba1f58a7f1317df6 to your computer and use it in GitHub Desktop.
Save lordfriend/4e8fba1f58a7f1317df6 to your computer and use it in GitHub Desktop.
selectable table row directive which support none-selectable td element
<table>
<tbody>
<tr selectab-tr="pickRow()">
<td>some data</td>
<td>some data</td>
<td class="none-selectable">
<a href="someurl">Click this link will not execute pickRow() function</a>
</td>
</tr>
</tbody>
</table>
/**
* Created by bob on 4/28/15.
*/
define([
'jquery',
'angular'
], function($, angular){
'use strict';
var selectableTable = angular.module('selectableTr', []);
/**
* setup a table row click event callback handler. will only fire when user click an td which doesn't
* have a `none-selectable` class.
* This directive is recommended for using with ng-repeat on tr element
*/
selectableTable.directive('selectableTr', ['$parse', function($parse) {
return {
restrict: 'A',
scope: false,
link: function($scope, $element, $attrs) {
var onClickFn = $parse($attrs.selectableTr);
$element.on('click', 'td:not(.none-selectable)', function(event) {
var callback = function() {
onClickFn($scope, {$event: event});
};
$scope.$apply(callback);
});
}
}
}]);
});
@alanerzhao
Copy link

good thank's

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment