Last active
February 15, 2016 15:55
-
-
Save wiedikerli/ac25593730b103bf6034 to your computer and use it in GitHub Desktop.
set default selection for smart table. Check: http://plnkr.co/edit/ImstnnRdtpaL4z1XQGG2?p=info
This file contains 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
app.directive('stDefaultSelection', function() { | |
return { | |
require: 'stTable', | |
restrict: 'A', | |
scope: { | |
selection: '=stDefaultSelection', | |
}, | |
link: function link(scope, element, attrs, controller) { | |
var pagination = null, | |
hasLoaded = false, | |
selectionMode = 'single'; | |
if (scope.selection != null) { | |
scope.$watch(function() { | |
pagination = controller.tableState().pagination; | |
if (pagination != null && pagination.number != null && hasLoaded == false) { | |
var rows = controller.getFilteredCollection(), | |
indexOfRow = angular.isNumber(scope.selection) ? scope.selection : rows.indexOf(scope.selection), | |
finalPage = Math.ceil(indexOfRow / pagination.number) - 1; // starts at zero | |
// select row | |
controller.select(rows[indexOfRow], selectionMode); | |
if (indexOfRow > -1) { | |
controller.slice(finalPage * pagination.number, pagination.number); | |
hasLoaded = true; | |
} | |
} | |
}, true); | |
} | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment