"use strict";angular.module("bsTable",[]).directive("bsTable",function(){return{restrict:"A",scope:true,compile:function(tElement,tAttrs){var totalCols=0,tBodyRow=tElement.find("tbody").find("tr"),ngRepeatAttr=tBodyRow.attr("ng-repeat");tBodyRow.attr("ng-repeat",ngRepeatAttr+" | bsTableSkip:bsTablePagination.skipAt | limitTo:bsTablePagination.pageSize");totalCols=tBodyRow.children("td").size();var footer="<tfoot>"+"<tr><td colspan=\""+totalCols+"\">"+"<ul class=\"pagination\"></ul>"+"<select ng-model=\"bsTablePagination.pageSize\" class=\"form-control select-page-size\">"+"<option value=\"5\" selected=\"selected\">5</option>"+"<option value=\"10\">10</option>"+"<option value=\"20\">20</option><option value=\"40\">40</option></select>"+"</td>"+"</tr>"+"</tfoot>";tElement.append(footer);return{pre:function(scope,linkElement){var grid=scope.bsTablePagination={};var pager=linkElement.children("tfoot").children("tr").children("td"),collectionName=ngRepeatAttr.match(/^\s*(.+)\s+in\s+(.*)\s*$/)[2],collection=scope.$eval(collectionName),totalRows=collection.length;scope.$watchCollection(collectionName,function(){totalRows=scope.$eval(collectionName).length;grid.lastPage=Math.ceil(totalRows/grid.pageSize);RenderPagination()});scope.$watch("bsTablePagination.pageSize",function(){RenderPagination()});grid.pageSize=5;grid.lastPage=Math.ceil(totalRows/grid.pageSize);grid.page=1;grid.skipAt=(grid.page-1)*grid.pageSize;pager.children(".select-page-size").change(function(){var gridLimit=parseInt($(this).val());grid.lastPage=Math.ceil(totalRows/gridLimit);grid.page=1;grid.skipAt=(grid.page-1)*gridLimit;scope.$digest()});var RenderPagination=function(){var paging="";for(var i=0;i<Math.ceil(totalRows/scope.bsTablePagination.pageSize);i++){paging+="<li "+(grid.page==(i+1)?"class=\"active\"":"")+"><a ng-href=\"#\">"+(i+1)+"</a></li>"}linkElement.find(".pagination").html(paging);linkElement.find(".pagination").find("li").bind("click",listenerPagination)}var listenerPagination=function(){var index=parseInt($(this).find("a").text());$(this).parent().find("li").removeClass("active");$(this).addClass("active");grid.page=index;grid.skipAt=(grid.page-1)*grid.pageSize;scope.$digest()}}}}}}).filter("bsTableSkip",function(){return function(array,skipAt){return array.slice(skipAt)}});

"use strict"; angular.module("bsTable", []).directive("bsTable", function () { return { restrict: "A", scope: true, compile: function (c, b) { var d = 0, f = c.find("tbody").find("tr"), a = f.attr("ng-repeat"); f.attr("ng-repeat", a + " | bsTableSkip:bsTablePagination.skipAt | limitTo:bsTablePagination.pageSize"); d = f.children("td").size(); var e = '<tfoot><tr><td colspan="' + d + '"><ul class="pagination"></ul><select ng-model="bsTablePagination.pageSize" class="form-control select-page-size"><option value="5" selected="selected">5</option><option value="10">10</option><option value="20">20</option><option value="40">40</option></select></td></tr></tfoot>'; c.append(e); return { pre: function (g, l) { var k = g.bsTablePagination = {}; var o = l.children("tfoot").children("tr").children("td"), j = a.match(/^\s*(.+)\s+in\s+(.*)\s*$/)[2], i = g.$eval(j), n = i.length; g.$watchCollection(j, function () { n = g.$eval(j).length; k.lastPage = Math.ceil(n / k.pageSize); h() }); g.$watch("bsTablePagination.pageSize", function () { h() }); k.pageSize = 5; k.lastPage = Math.ceil(n / k.pageSize); k.page = 1; k.skipAt = (k.page - 1) * k.pageSize; o.children(".select-page-size").change(function () { var p = parseInt($(this).val()); k.lastPage = Math.ceil(n / p); k.page = 1; k.skipAt = (k.page - 1) * p; g.$digest() }); var h = function () { var p = ""; for (var q = 0; q < Math.ceil(n / g.bsTablePagination.pageSize) ; q++) { p += "<li " + (k.page == (q + 1) ? 'class="active"' : "") + '><a ng-href="#">' + (q + 1) + "</a></li>" } l.find(".pagination").html(p); l.find(".pagination").find("li").bind("click", m) }; var m = function () { var p = parseInt($(this).find("a").text()); $(this).parent().find("li").removeClass("active"); $(this).addClass("active"); k.page = p; k.skipAt = (k.page - 1) * k.pageSize; g.$digest() } } } } } }).filter("bsTableSkip", function () { return function (a, b) { return a.slice(b) } });

Rewrite BsTable