Created
April 28, 2015 10:12
-
-
Save lordfriend/4e8fba1f58a7f1317df6 to your computer and use it in GitHub Desktop.
selectable table row directive which support none-selectable td element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); | |
}); | |
} | |
} | |
}]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good thank's