ris-table-sticky-header.js 1006 Bytes
Newer Older
eddie.woo's avatar
eddie.woo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*
sticky table header
*
usage:
*  <div data-ris-table-sticky-header style="max-height: 170px; overflow-x: hidden; overflow-y: auto; margin-bottom: 10px;">
*           <table id="transactions" class="csd-table csd-col8-right" style="display: table;">
*                <thead>
*                    <tr>
*/
commonModule.directive("risTableStickyHeader", ['$log', '$timeout', function ($log, $timeout) {
    'use strict';

    return function (scope, element, attrs) {
        // auto scroll
        if (attrs.scrollOn) {
            scope.$on(attrs.scrollOn, function (event, args) {
                // 35 for sticky header height
                element.scrollTop(element.scrollTop() - 35 + element.find('#' + args.target).closest('tr').position().top);
            });
        }

        $timeout(function () {
            element.find('table').floatThead({
                scrollContainer: function () {
                    return element;
                }
            });
        }, 1000);
    }
}]);