angular-smart-table
Advanced tools
Comparing version 2.1.8 to 2.1.9
## version 1.1.0 | ||
* allow binding on search predicate [https://github.com/lorenzofox3/Smart-Table/issues/142] (issue 142) | ||
* allow binding on search predicate ([#142](https://github.com/lorenzofox3/Smart-Table/issues/142)). | ||
Note that if you want to search against a property name you have now to put in under single quote otherwise it will be considered as a binding | ||
@@ -11,7 +11,7 @@ ```markup | ||
* fix #146 and #148, set stPipe before stPagination is called. Thanks [brianchance](https://github.com/brianchance) | ||
* fix [#146](https://github.com/lorenzofox3/Smart-Table/issues/146) and [#148](https://github.com/lorenzofox3/Smart-Table/issues/148), set stPipe before stPagination is called. Thanks [brianchance](https://github.com/brianchance) | ||
## version 1.2.1 | ||
* implement #149 (default sorting) | ||
* implement [#149](https://github.com/lorenzofox3/Smart-Table/issues/149) (default sorting) | ||
@@ -30,11 +30,11 @@ ## version 1.2.2 | ||
* fix #161 | ||
* fix [#161](https://github.com/lorenzofox3/Smart-Table/issues/161) | ||
## version 1.2.5 | ||
* fix #162 | ||
* fix [#162](https://github.com/lorenzofox3/Smart-Table/issues/162) | ||
## version 1.2.6 | ||
* fix #165 | ||
* fix [#165](https://github.com/lorenzofox3/Smart-Table/issues/165) | ||
* ability to overwrite class names for (st-sort-ascent and st-sort-descent) thanks to [replacement87](https://github.com/replacement87) | ||
@@ -44,3 +44,3 @@ | ||
* fix #167 | ||
* fix [#167](https://github.com/lorenzofox3/Smart-Table/issues/167) | ||
@@ -58,7 +58,7 @@ ## version 1.3.0 | ||
* ability to skip natural ordering state (ie fix #192) | ||
* ability to skip natural ordering state (ie fix [#192](https://github.com/lorenzofox3/Smart-Table/issues/192)) | ||
## versiokn 1.4.2 | ||
* fix #200, `this` in a custom pipe function does not refer to the table controller anymore, and the signature of a custom pipe function is | ||
* fix [#200](https://github.com/lorenzofox3/Smart-Table/issues/200), `this` in a custom pipe function does not refer to the table controller anymore, and the signature of a custom pipe function is | ||
```javascript | ||
@@ -81,4 +81,4 @@ function(tableState, tableController){ | ||
* merge #234, #218 | ||
* fix #233 #237 | ||
* merge [#234](https://github.com/lorenzofox3/Smart-Table/issues/234), [#218](https://github.com/lorenzofox3/Smart-Table/issues/218) | ||
* fix [#233](https://github.com/lorenzofox3/Smart-Table/issues/2332), [#237](https://github.com/lorenzofox3/Smart-Table/issues/237) | ||
@@ -88,24 +88,24 @@ ## version 1.4.6 | ||
* evaluate sort predicate as late as possible | ||
* fix #262 | ||
* fix [#262](https://github.com/lorenzofox3/Smart-Table/issues/262) | ||
## version 1.4.7 | ||
* fix #276 | ||
* fix [#276](https://github.com/lorenzofox3/Smart-Table/issues/276) | ||
## version 1.4.8 | ||
* fix #281 | ||
* fix [#281](https://github.com/lorenzofox3/Smart-Table/issues/281) | ||
## version 1.4.9 | ||
* fix #285 | ||
* fix [#285](https://github.com/lorenzofox3/Smart-Table/issues/285) | ||
## version 1.4.10 | ||
* fix #284 | ||
* fix #290 | ||
* fix [#284](https://github.com/lorenzofox3/Smart-Table/issues/284) | ||
* fix [#290](https://github.com/lorenzofox3/Smart-Table/issues/290) | ||
## version 1.4.11 | ||
* fix #296 | ||
* fix [#296](https://github.com/lorenzofox3/Smart-Table/issues/296) | ||
* add possibility to bind a callback when page changes | ||
@@ -131,3 +131,3 @@ | ||
* fix #328 | ||
* fix [#328](https://github.com/lorenzofox3/Smart-Table/issues/328) | ||
@@ -137,8 +137,8 @@ ## version 2.0.2 | ||
* add debounce to custom pipe function to make sure tableState is stable | ||
* fix #329 | ||
* fix [#329](https://github.com/lorenzofox3/Smart-Table/issues/329) | ||
## version 2.0.3 | ||
* implements #379 | ||
* fix #390 | ||
* implements [#379](https://github.com/lorenzofox3/Smart-Table/issues/379) | ||
* fix [#390](https://github.com/lorenzofox3/Smart-Table/issues/390) | ||
@@ -148,5 +148,5 @@ ## version 2.1.0 | ||
* support nested search (thanks to @jansabbe) | ||
* fix #254 | ||
* fix [#254](https://github.com/lorenzofox3/Smart-Table/issues/254) | ||
* fix wrong path to default config for stSkipNatural (@phuvo) | ||
* fix #406 | ||
* fix [#406](https://github.com/lorenzofox3/Smart-Table/issues/406) | ||
@@ -160,7 +160,7 @@ ## version 2.1.1 | ||
* improve build #461 [stanleyxu](https://github.com/stanleyxu2005) | ||
* improve build [#461](https://github.com/lorenzofox3/Smart-Table/issues/461) [stanleyxu](https://github.com/stanleyxu2005) | ||
## version 2.1.3 | ||
* fix #477 | ||
* fix [#477](https://github.com/lorenzofox3/Smart-Table/issues/477) | ||
@@ -174,9 +174,9 @@ ## version 2.1.4 | ||
* #544 | ||
* #533 | ||
* #515 | ||
* added multiple sort support to st-sort, [#544](https://github.com/lorenzofox3/Smart-Table/issues/544) | ||
* fix [#533](https://github.com/lorenzofox3/Smart-Table/issues/533) | ||
* fix [#515](https://github.com/lorenzofox3/Smart-Table/issues/515) | ||
## version 2.1.6 | ||
* #559 | ||
* fix [#559](https://github.com/lorenzofox3/Smart-Table/issues/559) | ||
@@ -183,0 +183,0 @@ ## version 2.1.7 |
/** | ||
* @version 2.1.8 | ||
* @version 2.1.9 | ||
* @license MIT | ||
@@ -11,3 +11,3 @@ */ | ||
'<nav ng-if="numPages && pages.length >= 2"><ul class="pagination">' + | ||
'<li ng-repeat="page in pages" ng-class="{active: page==currentPage}"><a href="javascript: void(0);" ng-click="selectPage(page)">{{page}}</a></li>' + | ||
'<li ng-repeat="page in pages" ng-class="{active: page==currentPage}"><a href="#" ng-click="selectPage(page); $event.preventDefault(); $event.stopPropagation();">{{page}}</a></li>' + | ||
'</ul></nav>'); | ||
@@ -43,4 +43,8 @@ }]); | ||
}); | ||
ng.module('smart-table') | ||
.controller('stTableController', ['$scope', '$parse', '$filter', '$attrs', function StTableController ($scope, $parse, $filter, $attrs) { | ||
ng.module('smart-table').controller('stTableController', [ | ||
'$scope', | ||
'$parse', | ||
'$filter', | ||
'$attrs', | ||
function StTableController($scope, $parse, $filter, $attrs) { | ||
var propertyName = $attrs.stTable; | ||
@@ -56,6 +60,3 @@ var displayGetter = $parse(propertyName); | ||
search: {}, | ||
pagination: { | ||
start: 0, | ||
totalItemCount: 0 | ||
} | ||
pagination: { start: 0, totalItemCount: 0 } | ||
}; | ||
@@ -67,7 +68,7 @@ var filtered; | ||
function copyRefs (src) { | ||
function copyRefs(src) { | ||
return src ? [].concat(src) : []; | ||
} | ||
function updateSafeCopy () { | ||
function updateSafeCopy() { | ||
safeCopy = copyRefs(safeGetter($scope)); | ||
@@ -79,3 +80,3 @@ if (pipeAfterSafeCopy === true) { | ||
function deepDelete (object, path) { | ||
function deepDelete(object, path) { | ||
if (path.indexOf('.') != -1) { | ||
@@ -85,3 +86,3 @@ var partials = path.split('.'); | ||
var parentPath = partials.join('.'); | ||
var parentObject = $parse(parentPath)(object) | ||
var parentObject = $parse(parentPath)(object); | ||
delete parentObject[key]; | ||
@@ -98,26 +99,35 @@ if (Object.keys(parentObject).length == 0) { | ||
safeGetter = $parse($attrs.stSafeSrc); | ||
$scope.$watch(function () { | ||
var safeSrc = safeGetter($scope); | ||
return safeSrc && safeSrc.length ? safeSrc[0] : undefined; | ||
}, function (newValue, oldValue) { | ||
if (newValue !== oldValue) { | ||
updateSafeCopy(); | ||
$scope.$watch( | ||
function() { | ||
var safeSrc = safeGetter($scope); | ||
return safeSrc && safeSrc.length ? safeSrc[0] : undefined; | ||
}, | ||
function(newValue, oldValue) { | ||
if (newValue !== oldValue) { | ||
updateSafeCopy(); | ||
} | ||
} | ||
}); | ||
$scope.$watch(function () { | ||
var safeSrc = safeGetter($scope); | ||
return safeSrc ? safeSrc.length : 0; | ||
}, function (newValue, oldValue) { | ||
if (newValue !== safeCopy.length) { | ||
updateSafeCopy(); | ||
); | ||
$scope.$watch( | ||
function() { | ||
var safeSrc = safeGetter($scope); | ||
return safeSrc ? safeSrc.length : 0; | ||
}, | ||
function(newValue, oldValue) { | ||
if (newValue !== safeCopy.length) { | ||
updateSafeCopy(); | ||
} | ||
} | ||
}); | ||
$scope.$watch(function () { | ||
return safeGetter($scope); | ||
}, function (newValue, oldValue) { | ||
if (newValue !== oldValue) { | ||
tableState.pagination.start = 0; | ||
updateSafeCopy(); | ||
); | ||
$scope.$watch( | ||
function() { | ||
return safeGetter($scope); | ||
}, | ||
function(newValue, oldValue) { | ||
if (newValue !== oldValue) { | ||
tableState.pagination.start = 0; | ||
updateSafeCopy(); | ||
} | ||
} | ||
}); | ||
); | ||
} | ||
@@ -130,3 +140,3 @@ | ||
*/ | ||
this.sortBy = function sortBy (predicate, reverse) { | ||
this.sortBy = function sortBy(predicate, reverse) { | ||
tableState.sort.predicate = predicate; | ||
@@ -149,4 +159,5 @@ tableState.sort.reverse = reverse === true; | ||
* @param {String} [predicate] - the property name against you want to check the match, otherwise it will search on all properties | ||
* @param {String | Function } [comparator] - a comparator to pass to the filter for the (pass true for stric mode) | ||
*/ | ||
this.search = function search (input, predicate) { | ||
this.search = function search(input, predicate, comparator) { | ||
var predicateObject = tableState.search.predicateObject || {}; | ||
@@ -169,14 +180,27 @@ var prop = predicate ? predicate : '$'; | ||
*/ | ||
this.pipe = function pipe () { | ||
this.pipe = function pipe() { | ||
var pagination = tableState.pagination; | ||
var output; | ||
filtered = tableState.search.predicateObject ? filter(safeCopy, tableState.search.predicateObject) : safeCopy; | ||
filtered = tableState.search.predicateObject | ||
? filter(safeCopy, tableState.search.predicateObject) | ||
: safeCopy; | ||
if (tableState.sort.predicate) { | ||
filtered = orderBy(filtered, tableState.sort.predicate, tableState.sort.reverse); | ||
filtered = orderBy( | ||
filtered, | ||
tableState.sort.predicate, | ||
tableState.sort.reverse | ||
); | ||
} | ||
pagination.totalItemCount = filtered.length; | ||
if (pagination.number !== undefined) { | ||
pagination.numberOfPages = filtered.length > 0 ? Math.ceil(filtered.length / pagination.number) : 1; | ||
pagination.start = pagination.start >= filtered.length ? (pagination.numberOfPages - 1) * pagination.number : pagination.start; | ||
output = filtered.slice(pagination.start, pagination.start + parseInt(pagination.number)); | ||
pagination.numberOfPages = filtered.length > 0 | ||
? Math.ceil(filtered.length / pagination.number) | ||
: 1; | ||
pagination.start = pagination.start >= filtered.length | ||
? (pagination.numberOfPages - 1) * pagination.number | ||
: pagination.start; | ||
output = filtered.slice( | ||
pagination.start, | ||
pagination.start + parseInt(pagination.number) | ||
); | ||
} | ||
@@ -191,3 +215,3 @@ displaySetter($scope, output || filtered); | ||
*/ | ||
this.select = function select (row, mode) { | ||
this.select = function select(row, mode) { | ||
var rows = copyRefs(displayGetter($scope)); | ||
@@ -214,3 +238,3 @@ var index = rows.indexOf(row); | ||
*/ | ||
this.slice = function splice (start, number) { | ||
this.slice = function splice(start, number) { | ||
tableState.pagination.start = start; | ||
@@ -225,7 +249,7 @@ tableState.pagination.number = number; | ||
*/ | ||
this.tableState = function getTableState () { | ||
this.tableState = function getTableState() { | ||
return tableState; | ||
}; | ||
this.getFilteredCollection = function getFilteredCollection () { | ||
this.getFilteredCollection = function getFilteredCollection() { | ||
return filtered || safeCopy; | ||
@@ -238,3 +262,3 @@ }; | ||
*/ | ||
this.setFilterFunction = function setFilterFunction (filterName) { | ||
this.setFilterFunction = function setFilterFunction(filterName) { | ||
filter = $filter(filterName); | ||
@@ -247,3 +271,3 @@ }; | ||
*/ | ||
this.setSortFunction = function setSortFunction (sortFunctionName) { | ||
this.setSortFunction = function setSortFunction(sortFunctionName) { | ||
orderBy = $filter(sortFunctionName); | ||
@@ -256,22 +280,21 @@ }; | ||
*/ | ||
this.preventPipeOnWatch = function preventPipe () { | ||
this.preventPipeOnWatch = function preventPipe() { | ||
pipeAfterSafeCopy = false; | ||
}; | ||
}]) | ||
.directive('stTable', function () { | ||
return { | ||
restrict: 'A', | ||
controller: 'stTableController', | ||
link: function (scope, element, attr, ctrl) { | ||
} | ||
]).directive('stTable', function() { | ||
return { | ||
restrict: 'A', | ||
controller: 'stTableController', | ||
link: function(scope, element, attr, ctrl) { | ||
if (attr.stSetFilter) { | ||
ctrl.setFilterFunction(attr.stSetFilter); | ||
} | ||
if (attr.stSetFilter) { | ||
ctrl.setFilterFunction(attr.stSetFilter); | ||
} | ||
if (attr.stSetSort) { | ||
ctrl.setSortFunction(attr.stSetSort); | ||
} | ||
if (attr.stSetSort) { | ||
ctrl.setSortFunction(attr.stSetSort); | ||
} | ||
}; | ||
}); | ||
} | ||
}; | ||
}); | ||
@@ -397,3 +420,5 @@ ng.module('smart-table') | ||
} else { | ||
promise = $timeout(func, throttle); | ||
promise = $timeout(function(){ | ||
func(); | ||
}, throttle); | ||
} | ||
@@ -400,0 +425,0 @@ } |
/** | ||
* @version 2.1.8 | ||
* @version 2.1.9 | ||
* @license MIT | ||
*/ | ||
!function(t,e){"use strict";t.module("smart-table",[]).run(["$templateCache",function(t){t.put("template/smart-table/pagination.html",'<nav ng-if="numPages && pages.length >= 2"><ul class="pagination"><li ng-repeat="page in pages" ng-class="{active: page==currentPage}"><a href="javascript: void(0);" ng-click="selectPage(page)">{{page}}</a></li></ul></nav>')}]),t.module("smart-table").constant("stConfig",{pagination:{template:"template/smart-table/pagination.html",itemsByPage:10,displayedPages:5},search:{delay:400,inputEvent:"input"},select:{mode:"single",selectedClass:"st-selected"},sort:{ascentClass:"st-sort-ascent",descentClass:"st-sort-descent",descendingFirst:!1,skipNatural:!1,delay:300},pipe:{delay:100}}),t.module("smart-table").controller("stTableController",["$scope","$parse","$filter","$attrs",function(a,n,s,i){function r(t){return t?[].concat(t):[]}function l(){b=r(o(a)),v===!0&&S.pipe()}function c(t,e){if(-1!=e.indexOf(".")){var a=e.split("."),s=a.pop(),i=a.join("."),r=n(i)(t);delete r[s],0==Object.keys(r).length&&c(t,i)}else delete t[e]}var o,u,p,g=i.stTable,d=n(g),f=d.assign,m=s("orderBy"),h=s("filter"),b=r(d(a)),P={sort:{},search:{},pagination:{start:0,totalItemCount:0}},v=!0,S=this;i.stSafeSrc&&(o=n(i.stSafeSrc),a.$watch(function(){var t=o(a);return t&&t.length?t[0]:e},function(t,e){t!==e&&l()}),a.$watch(function(){var t=o(a);return t?t.length:0},function(t){t!==b.length&&l()}),a.$watch(function(){return o(a)},function(t,e){t!==e&&(P.pagination.start=0,l())})),this.sortBy=function(e,a){return P.sort.predicate=e,P.sort.reverse=a===!0,t.isFunction(e)?P.sort.functionName=e.name:delete P.sort.functionName,P.pagination.start=0,this.pipe()},this.search=function(e,a){var s=P.search.predicateObject||{},i=a?a:"$";return e=t.isString(e)?e.trim():e,n(i).assign(s,e),e||c(s,i),P.search.predicateObject=s,P.pagination.start=0,this.pipe()},this.pipe=function(){var t,n=P.pagination;u=P.search.predicateObject?h(b,P.search.predicateObject):b,P.sort.predicate&&(u=m(u,P.sort.predicate,P.sort.reverse)),n.totalItemCount=u.length,n.number!==e&&(n.numberOfPages=u.length>0?Math.ceil(u.length/n.number):1,n.start=n.start>=u.length?(n.numberOfPages-1)*n.number:n.start,t=u.slice(n.start,n.start+parseInt(n.number))),f(a,t||u)},this.select=function(t,n){var s=r(d(a)),i=s.indexOf(t);-1!==i&&("single"===n?(t.isSelected=t.isSelected!==!0,p&&(p.isSelected=!1),p=t.isSelected===!0?t:e):s[i].isSelected=!s[i].isSelected)},this.slice=function(t,e){return P.pagination.start=t,P.pagination.number=e,this.pipe()},this.tableState=function(){return P},this.getFilteredCollection=function(){return u||b},this.setFilterFunction=function(t){h=s(t)},this.setSortFunction=function(t){m=s(t)},this.preventPipeOnWatch=function(){v=!1}}]).directive("stTable",function(){return{restrict:"A",controller:"stTableController",link:function(t,e,a,n){a.stSetFilter&&n.setFilterFunction(a.stSetFilter),a.stSetSort&&n.setSortFunction(a.stSetSort)}}}),t.module("smart-table").directive("stSearch",["stConfig","$timeout","$parse",function(t,e,a){return{require:"^stTable",link:function(n,s,i,r){var l=r,c=null,o=i.stDelay||t.search.delay,u=i.stInputEvent||t.search.inputEvent;i.$observe("stSearch",function(t,e){var a=s[0].value;t!==e&&a&&(r.tableState().search={},l.search(a,t))}),n.$watch(function(){return r.tableState().search},function(t){var e=i.stSearch||"$";t.predicateObject&&a(e)(t.predicateObject)!==s[0].value&&(s[0].value=a(e)(t.predicateObject)||"")},!0),s.bind(u,function(t){t=t.originalEvent||t,null!==c&&e.cancel(c),c=e(function(){l.search(t.target.value,i.stSearch||""),c=null},o)})}}}]),t.module("smart-table").directive("stSelectRow",["stConfig",function(t){return{restrict:"A",require:"^stTable",scope:{row:"=stSelectRow"},link:function(e,a,n,s){var i=n.stSelectMode||t.select.mode;a.bind("click",function(){e.$apply(function(){s.select(e.row,i)})}),e.$watch("row.isSelected",function(e){e===!0?a.addClass(t.select.selectedClass):a.removeClass(t.select.selectedClass)})}}}]),t.module("smart-table").directive("stSort",["stConfig","$parse","$timeout",function(a,n,s){return{restrict:"A",require:"^stTable",link:function(i,r,l,c){function o(){P?d=0===d?2:d-1:d++;var e;p=t.isFunction(g(i))||t.isArray(g(i))?g(i):l.stSort,d%3===0&&!!b!=!0?(d=0,c.tableState().sort={},c.tableState().pagination.start=0,e=c.pipe.bind(c)):e=c.sortBy.bind(c,p,d%2===0),null!==v&&s.cancel(v),0>S?e():v=s(e,S)}var u,p=l.stSort,g=n(p),d=0,f=l.stClassAscent||a.sort.ascentClass,m=l.stClassDescent||a.sort.descentClass,h=[f,m],b=l.stSkipNatural!==e?l.stSkipNatural:a.sort.skipNatural,P=l.stDescendingFirst!==e?l.stDescendingFirst:a.sort.descendingFirst,v=null,S=l.stDelay||a.sort.delay;l.stSortDefault&&(u=i.$eval(l.stSortDefault)!==e?i.$eval(l.stSortDefault):l.stSortDefault),r.bind("click",function(){p&&i.$apply(o)}),u&&(d="reverse"===u?1:0,o()),i.$watch(function(){return c.tableState().sort},function(t){t.predicate!==p?(d=0,r.removeClass(f).removeClass(m)):(d=t.reverse===!0?2:1,r.removeClass(h[d%2]).addClass(h[d-1]))},!0)}}}]),t.module("smart-table").directive("stPagination",["stConfig",function(t){return{restrict:"EA",require:"^stTable",scope:{stItemsByPage:"=?",stDisplayedPages:"=?",stPageChange:"&"},templateUrl:function(e,a){return a.stTemplate?a.stTemplate:t.pagination.template},link:function(e,a,n,s){function i(){var t,a,n=s.tableState().pagination,i=1,r=e.currentPage;for(e.totalItemCount=n.totalItemCount,e.currentPage=Math.floor(n.start/n.number)+1,i=Math.max(i,e.currentPage-Math.abs(Math.floor(e.stDisplayedPages/2))),t=i+e.stDisplayedPages,t>n.numberOfPages&&(t=n.numberOfPages+1,i=Math.max(1,t-e.stDisplayedPages)),e.pages=[],e.numPages=n.numberOfPages,a=i;t>a;a++)e.pages.push(a);r!==e.currentPage&&e.stPageChange({newPage:e.currentPage})}e.stItemsByPage=e.stItemsByPage?+e.stItemsByPage:t.pagination.itemsByPage,e.stDisplayedPages=e.stDisplayedPages?+e.stDisplayedPages:t.pagination.displayedPages,e.currentPage=1,e.pages=[],e.$watch(function(){return s.tableState().pagination},i,!0),e.$watch("stItemsByPage",function(t,a){t!==a&&e.selectPage(1)}),e.$watch("stDisplayedPages",i),e.selectPage=function(t){t>0&&t<=e.numPages&&s.slice((t-1)*e.stItemsByPage,e.stItemsByPage)},s.tableState().pagination.number||s.slice(0,e.stItemsByPage)}}}]),t.module("smart-table").directive("stPipe",["stConfig","$timeout",function(e,a){return{require:"stTable",scope:{stPipe:"="},link:{pre:function(n,s,i,r){var l=null;t.isFunction(n.stPipe)&&(r.preventPipeOnWatch(),r.pipe=function(){return null!==l&&a.cancel(l),l=a(function(){n.stPipe(r.tableState(),r)},e.pipe.delay)})},post:function(t,e,a,n){n.pipe()}}}}])}(angular); | ||
!function(t,e){"use strict";t.module("smart-table",[]).run(["$templateCache",function(t){t.put("template/smart-table/pagination.html",'<nav ng-if="numPages && pages.length >= 2"><ul class="pagination"><li ng-repeat="page in pages" ng-class="{active: page==currentPage}"><a href="#" ng-click="selectPage(page); $event.preventDefault(); $event.stopPropagation();">{{page}}</a></li></ul></nav>')}]),t.module("smart-table").constant("stConfig",{pagination:{template:"template/smart-table/pagination.html",itemsByPage:10,displayedPages:5},search:{delay:400,inputEvent:"input"},select:{mode:"single",selectedClass:"st-selected"},sort:{ascentClass:"st-sort-ascent",descentClass:"st-sort-descent",descendingFirst:!1,skipNatural:!1,delay:300},pipe:{delay:100}}),t.module("smart-table").controller("stTableController",["$scope","$parse","$filter","$attrs",function(e,a,n,s){function i(t){return t?[].concat(t):[]}function r(){h=i(c(e)),!0===v&&P.pipe()}function l(t,e){if(-1!=e.indexOf(".")){var n=e.split("."),s=n.pop(),i=n.join("."),r=a(i)(t);delete r[s],0==Object.keys(r).length&&l(t,i)}else delete t[e]}var c,o,u,p=s.stTable,g=a(p),d=g.assign,f=n("orderBy"),m=n("filter"),h=i(g(e)),b={sort:{},search:{},pagination:{start:0,totalItemCount:0}},v=!0,P=this;s.stSafeSrc&&(c=a(s.stSafeSrc),e.$watch(function(){var t=c(e);return t&&t.length?t[0]:void 0},function(t,e){t!==e&&r()}),e.$watch(function(){var t=c(e);return t?t.length:0},function(t,e){t!==h.length&&r()}),e.$watch(function(){return c(e)},function(t,e){t!==e&&(b.pagination.start=0,r())})),this.sortBy=function(e,a){return b.sort.predicate=e,b.sort.reverse=!0===a,t.isFunction(e)?b.sort.functionName=e.name:delete b.sort.functionName,b.pagination.start=0,this.pipe()},this.search=function(e,n,s){var i=b.search.predicateObject||{},r=n||"$";return e=t.isString(e)?e.trim():e,a(r).assign(i,e),e||l(i,r),b.search.predicateObject=i,b.pagination.start=0,this.pipe()},this.pipe=function(){var t,a=b.pagination;o=b.search.predicateObject?m(h,b.search.predicateObject):h,b.sort.predicate&&(o=f(o,b.sort.predicate,b.sort.reverse)),a.totalItemCount=o.length,void 0!==a.number&&(a.numberOfPages=o.length>0?Math.ceil(o.length/a.number):1,a.start=a.start>=o.length?(a.numberOfPages-1)*a.number:a.start,t=o.slice(a.start,a.start+parseInt(a.number))),d(e,t||o)},this.select=function(t,a){var n=i(g(e)),s=n.indexOf(t);-1!==s&&("single"===a?(t.isSelected=!0!==t.isSelected,u&&(u.isSelected=!1),u=!0===t.isSelected?t:void 0):n[s].isSelected=!n[s].isSelected)},this.slice=function(t,e){return b.pagination.start=t,b.pagination.number=e,this.pipe()},this.tableState=function(){return b},this.getFilteredCollection=function(){return o||h},this.setFilterFunction=function(t){m=n(t)},this.setSortFunction=function(t){f=n(t)},this.preventPipeOnWatch=function(){v=!1}}]).directive("stTable",function(){return{restrict:"A",controller:"stTableController",link:function(t,e,a,n){a.stSetFilter&&n.setFilterFunction(a.stSetFilter),a.stSetSort&&n.setSortFunction(a.stSetSort)}}}),t.module("smart-table").directive("stSearch",["stConfig","$timeout","$parse",function(t,e,a){return{require:"^stTable",link:function(n,s,i,r){var l=r,c=null,o=i.stDelay||t.search.delay,u=i.stInputEvent||t.search.inputEvent;i.$observe("stSearch",function(t,e){var a=s[0].value;t!==e&&a&&(r.tableState().search={},l.search(a,t))}),n.$watch(function(){return r.tableState().search},function(t,e){var n=i.stSearch||"$";t.predicateObject&&a(n)(t.predicateObject)!==s[0].value&&(s[0].value=a(n)(t.predicateObject)||"")},!0),s.bind(u,function(t){t=t.originalEvent||t,null!==c&&e.cancel(c),c=e(function(){l.search(t.target.value,i.stSearch||""),c=null},o)})}}}]),t.module("smart-table").directive("stSelectRow",["stConfig",function(t){return{restrict:"A",require:"^stTable",scope:{row:"=stSelectRow"},link:function(e,a,n,s){var i=n.stSelectMode||t.select.mode;a.bind("click",function(){e.$apply(function(){s.select(e.row,i)})}),e.$watch("row.isSelected",function(e){!0===e?a.addClass(t.select.selectedClass):a.removeClass(t.select.selectedClass)})}}}]),t.module("smart-table").directive("stSort",["stConfig","$parse","$timeout",function(e,a,n){return{restrict:"A",require:"^stTable",link:function(s,i,r,l){function c(){b?g=0===g?2:g-1:g++;var e;u=t.isFunction(p(s))||t.isArray(p(s))?p(s):r.stSort,g%3==0&&!0!=!!h?(g=0,l.tableState().sort={},l.tableState().pagination.start=0,e=l.pipe.bind(l)):e=l.sortBy.bind(l,u,g%2==0),null!==v&&n.cancel(v),P<0?e():v=n(function(){e()},P)}var o,u=r.stSort,p=a(u),g=0,d=r.stClassAscent||e.sort.ascentClass,f=r.stClassDescent||e.sort.descentClass,m=[d,f],h=void 0!==r.stSkipNatural?r.stSkipNatural:e.sort.skipNatural,b=void 0!==r.stDescendingFirst?r.stDescendingFirst:e.sort.descendingFirst,v=null,P=r.stDelay||e.sort.delay;r.stSortDefault&&(o=void 0!==s.$eval(r.stSortDefault)?s.$eval(r.stSortDefault):r.stSortDefault),i.bind("click",function(){u&&s.$apply(c)}),o&&(g="reverse"===o?1:0,c()),s.$watch(function(){return l.tableState().sort},function(t){t.predicate!==u?(g=0,i.removeClass(d).removeClass(f)):(g=!0===t.reverse?2:1,i.removeClass(m[g%2]).addClass(m[g-1]))},!0)}}}]),t.module("smart-table").directive("stPagination",["stConfig",function(t){return{restrict:"EA",require:"^stTable",scope:{stItemsByPage:"=?",stDisplayedPages:"=?",stPageChange:"&"},templateUrl:function(e,a){return a.stTemplate?a.stTemplate:t.pagination.template},link:function(e,a,n,s){function i(){var t,a,n=s.tableState().pagination,i=1,r=e.currentPage;for(e.totalItemCount=n.totalItemCount,e.currentPage=Math.floor(n.start/n.number)+1,(t=(i=Math.max(i,e.currentPage-Math.abs(Math.floor(e.stDisplayedPages/2))))+e.stDisplayedPages)>n.numberOfPages&&(t=n.numberOfPages+1,i=Math.max(1,t-e.stDisplayedPages)),e.pages=[],e.numPages=n.numberOfPages,a=i;a<t;a++)e.pages.push(a);r!==e.currentPage&&e.stPageChange({newPage:e.currentPage})}e.stItemsByPage=e.stItemsByPage?+e.stItemsByPage:t.pagination.itemsByPage,e.stDisplayedPages=e.stDisplayedPages?+e.stDisplayedPages:t.pagination.displayedPages,e.currentPage=1,e.pages=[],e.$watch(function(){return s.tableState().pagination},i,!0),e.$watch("stItemsByPage",function(t,a){t!==a&&e.selectPage(1)}),e.$watch("stDisplayedPages",i),e.selectPage=function(t){t>0&&t<=e.numPages&&s.slice((t-1)*e.stItemsByPage,e.stItemsByPage)},s.tableState().pagination.number||s.slice(0,e.stItemsByPage)}}}]),t.module("smart-table").directive("stPipe",["stConfig","$timeout",function(e,a){return{require:"stTable",scope:{stPipe:"="},link:{pre:function(n,s,i,r){var l=null;t.isFunction(n.stPipe)&&(r.preventPipeOnWatch(),r.pipe=function(){return null!==l&&a.cancel(l),l=a(function(){n.stPipe(r.tableState(),r)},e.pipe.delay)})},post:function(t,e,a,n){n.pipe()}}}}])}(angular); | ||
//# sourceMappingURL=smart-table.min.js.map |
@@ -5,6 +5,4 @@ var gulp = require('gulp'); | ||
var karma = require('karma').server; | ||
var jshint = require('gulp-jshint'); | ||
var insert = require('gulp-insert'); | ||
var sourcemaps = require('gulp-sourcemaps'); | ||
var stylish = require('jshint-stylish'); | ||
var packageJson = require('./package.json'); | ||
@@ -20,10 +18,3 @@ var pluginList = ['stSearch', 'stSelectRow', 'stSort', 'stPagination', 'stPipe']; | ||
//just as indication | ||
gulp.task('lint', function () { | ||
gulp.src(src) | ||
.pipe(jshint()) | ||
.pipe(jshint.reporter(stylish)); | ||
}); | ||
gulp.task('karma-CI', function (done) { | ||
@@ -30,0 +21,0 @@ var conf = require('./test/karma.common.js'); |
@@ -5,7 +5,7 @@ ## Hello contributor ! | ||
1) [] I have searched through the issue section and on [stackoverflow](http://stackoverflow.com/questions/tagged/smart-table?sort=newest&pageSize=30) if my issue has already been raised. | ||
2) [] I have provided Angular version. | ||
3) [] I have provided Smart table version. | ||
4) [] I have set a precise description of my problem, mentioning the expected result. | ||
5) [] I have given a way to reproduce my issue, by providing a <strong>running example</strong>, I can use [plunkr](http://plnkr.co/). Note if you want to mimic ajax loading behaviour you can use [$timeout](https://docs.angularjs.org/api/ng/service/$timeout) angular service or [$httpBackend](https://docs.angularjs.org/api/ng/service/$httpBackend). | ||
- [ ] I have searched through the issue section and on [stackoverflow](http://stackoverflow.com/questions/tagged/smart-table?sort=newest&pageSize=30) if my issue has already been raised. | ||
- [ ] I have provided Angular version. | ||
- [ ] I have provided Smart table version. | ||
- [ ] I have set a precise description of my problem, mentioning the expected result. | ||
- [ ] I have given a way to reproduce my issue, by providing a <strong>running example</strong>, I can use [plunkr](http://plnkr.co/). Note if you want to mimic ajax loading behaviour you can use [$timeout](https://docs.angularjs.org/api/ng/service/$timeout) angular service or [$httpBackend](https://docs.angularjs.org/api/ng/service/$httpBackend). | ||
@@ -16,2 +16,2 @@ Note that it not all the above checkbox can be marked as checked the issue will immediately be closed. Thanks for your understanding. | ||
Thanks again for your contribution. | ||
Thanks again for your contribution. |
{ | ||
"name": "angular-smart-table", | ||
"version": "2.1.8", | ||
"version": "2.1.9", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node ./node_modules/.bin/gulp karma-CI" | ||
"test": "node ./node_modules/.bin/gulp karma-CI", | ||
"build": "node ./node_modules/.bin/gulp build" | ||
}, | ||
@@ -16,15 +17,17 @@ "repository": { | ||
"devDependencies": { | ||
"angular": "^1.6.4", | ||
"angular-mocks": "^1.6.4", | ||
"gulp": "^3.8.7", | ||
"gulp-concat": "^2.3.4", | ||
"gulp-insert": "^0.4.0", | ||
"gulp-jshint": "^1.8.4", | ||
"gulp-sourcemaps": "^1.3.0", | ||
"gulp-uglify": "^0.3.1", | ||
"jshint-stylish": "^0.4.0", | ||
"karma": "^0.12.21", | ||
"karma-chrome-launcher": "^0.1.4", | ||
"karma-coverage": "^0.2.6", | ||
"karma-jasmine": "^0.1.5", | ||
"karma-phantomjs-launcher": "^0.1.4" | ||
"gulp-insert": "^0.5.0", | ||
"gulp-sourcemaps": "^2.6.0", | ||
"gulp-uglify": "^3.0.0", | ||
"jasmine-core": "^2.6.3", | ||
"jquery": "^3.2.1", | ||
"karma": "^1.7.0", | ||
"karma-chrome-launcher": "^2.1.1", | ||
"karma-coverage": "^1.1.1", | ||
"karma-jasmine": "^1.1.0", | ||
"karma-phantomjs-launcher": "^1.0.4" | ||
} | ||
} |
[![Build Status](https://travis-ci.org/lorenzofox3/Smart-Table.svg?branch=master)](https://travis-ci.org/lorenzofox3/Smart-Table) | ||
# Smart Table | ||
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/lorenzofox3/Smart-Table?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
@@ -32,2 +31,4 @@ Smart Table is a table module for angular js. It allows you to quickly compose your table in a declarative way including sorting, filtering, row selection, and pagination. | ||
You can also install using NPM `npm install angular-smart-table`, so you can use with browserify or webpack | ||
## Test | ||
@@ -53,3 +54,3 @@ | ||
> Copyright (C) 2015 Laurent Renard. | ||
> Copyright (C) 2016 Laurent Renard. | ||
> | ||
@@ -56,0 +57,0 @@ > Permission is hereby granted, free of charge, to any person |
ng.module('smart-table', []).run(['$templateCache', function ($templateCache) { | ||
$templateCache.put('template/smart-table/pagination.html', | ||
'<nav ng-if="numPages && pages.length >= 2"><ul class="pagination">' + | ||
'<li ng-repeat="page in pages" ng-class="{active: page==currentPage}"><a href="javascript: void(0);" ng-click="selectPage(page)">{{page}}</a></li>' + | ||
'<li ng-repeat="page in pages" ng-class="{active: page==currentPage}"><a href="#" ng-click="selectPage(page); $event.preventDefault(); $event.stopPropagation();">{{page}}</a></li>' + | ||
'</ul></nav>'); | ||
}]); | ||
@@ -49,3 +49,5 @@ ng.module('smart-table') | ||
} else { | ||
promise = $timeout(func, throttle); | ||
promise = $timeout(function(){ | ||
func(); | ||
}, throttle); | ||
} | ||
@@ -52,0 +54,0 @@ } |
@@ -1,3 +0,7 @@ | ||
ng.module('smart-table') | ||
.controller('stTableController', ['$scope', '$parse', '$filter', '$attrs', function StTableController ($scope, $parse, $filter, $attrs) { | ||
ng.module('smart-table').controller('stTableController', [ | ||
'$scope', | ||
'$parse', | ||
'$filter', | ||
'$attrs', | ||
function StTableController($scope, $parse, $filter, $attrs) { | ||
var propertyName = $attrs.stTable; | ||
@@ -13,6 +17,3 @@ var displayGetter = $parse(propertyName); | ||
search: {}, | ||
pagination: { | ||
start: 0, | ||
totalItemCount: 0 | ||
} | ||
pagination: { start: 0, totalItemCount: 0 } | ||
}; | ||
@@ -24,7 +25,7 @@ var filtered; | ||
function copyRefs (src) { | ||
function copyRefs(src) { | ||
return src ? [].concat(src) : []; | ||
} | ||
function updateSafeCopy () { | ||
function updateSafeCopy() { | ||
safeCopy = copyRefs(safeGetter($scope)); | ||
@@ -36,3 +37,3 @@ if (pipeAfterSafeCopy === true) { | ||
function deepDelete (object, path) { | ||
function deepDelete(object, path) { | ||
if (path.indexOf('.') != -1) { | ||
@@ -42,3 +43,3 @@ var partials = path.split('.'); | ||
var parentPath = partials.join('.'); | ||
var parentObject = $parse(parentPath)(object) | ||
var parentObject = $parse(parentPath)(object); | ||
delete parentObject[key]; | ||
@@ -55,26 +56,35 @@ if (Object.keys(parentObject).length == 0) { | ||
safeGetter = $parse($attrs.stSafeSrc); | ||
$scope.$watch(function () { | ||
var safeSrc = safeGetter($scope); | ||
return safeSrc && safeSrc.length ? safeSrc[0] : undefined; | ||
}, function (newValue, oldValue) { | ||
if (newValue !== oldValue) { | ||
updateSafeCopy(); | ||
$scope.$watch( | ||
function() { | ||
var safeSrc = safeGetter($scope); | ||
return safeSrc && safeSrc.length ? safeSrc[0] : undefined; | ||
}, | ||
function(newValue, oldValue) { | ||
if (newValue !== oldValue) { | ||
updateSafeCopy(); | ||
} | ||
} | ||
}); | ||
$scope.$watch(function () { | ||
var safeSrc = safeGetter($scope); | ||
return safeSrc ? safeSrc.length : 0; | ||
}, function (newValue, oldValue) { | ||
if (newValue !== safeCopy.length) { | ||
updateSafeCopy(); | ||
); | ||
$scope.$watch( | ||
function() { | ||
var safeSrc = safeGetter($scope); | ||
return safeSrc ? safeSrc.length : 0; | ||
}, | ||
function(newValue, oldValue) { | ||
if (newValue !== safeCopy.length) { | ||
updateSafeCopy(); | ||
} | ||
} | ||
}); | ||
$scope.$watch(function () { | ||
return safeGetter($scope); | ||
}, function (newValue, oldValue) { | ||
if (newValue !== oldValue) { | ||
tableState.pagination.start = 0; | ||
updateSafeCopy(); | ||
); | ||
$scope.$watch( | ||
function() { | ||
return safeGetter($scope); | ||
}, | ||
function(newValue, oldValue) { | ||
if (newValue !== oldValue) { | ||
tableState.pagination.start = 0; | ||
updateSafeCopy(); | ||
} | ||
} | ||
}); | ||
); | ||
} | ||
@@ -87,3 +97,3 @@ | ||
*/ | ||
this.sortBy = function sortBy (predicate, reverse) { | ||
this.sortBy = function sortBy(predicate, reverse) { | ||
tableState.sort.predicate = predicate; | ||
@@ -106,4 +116,5 @@ tableState.sort.reverse = reverse === true; | ||
* @param {String} [predicate] - the property name against you want to check the match, otherwise it will search on all properties | ||
* @param {String | Function } [comparator] - a comparator to pass to the filter for the (pass true for stric mode) | ||
*/ | ||
this.search = function search (input, predicate) { | ||
this.search = function search(input, predicate, comparator) { | ||
var predicateObject = tableState.search.predicateObject || {}; | ||
@@ -126,14 +137,27 @@ var prop = predicate ? predicate : '$'; | ||
*/ | ||
this.pipe = function pipe () { | ||
this.pipe = function pipe() { | ||
var pagination = tableState.pagination; | ||
var output; | ||
filtered = tableState.search.predicateObject ? filter(safeCopy, tableState.search.predicateObject) : safeCopy; | ||
filtered = tableState.search.predicateObject | ||
? filter(safeCopy, tableState.search.predicateObject) | ||
: safeCopy; | ||
if (tableState.sort.predicate) { | ||
filtered = orderBy(filtered, tableState.sort.predicate, tableState.sort.reverse); | ||
filtered = orderBy( | ||
filtered, | ||
tableState.sort.predicate, | ||
tableState.sort.reverse | ||
); | ||
} | ||
pagination.totalItemCount = filtered.length; | ||
if (pagination.number !== undefined) { | ||
pagination.numberOfPages = filtered.length > 0 ? Math.ceil(filtered.length / pagination.number) : 1; | ||
pagination.start = pagination.start >= filtered.length ? (pagination.numberOfPages - 1) * pagination.number : pagination.start; | ||
output = filtered.slice(pagination.start, pagination.start + parseInt(pagination.number)); | ||
pagination.numberOfPages = filtered.length > 0 | ||
? Math.ceil(filtered.length / pagination.number) | ||
: 1; | ||
pagination.start = pagination.start >= filtered.length | ||
? (pagination.numberOfPages - 1) * pagination.number | ||
: pagination.start; | ||
output = filtered.slice( | ||
pagination.start, | ||
pagination.start + parseInt(pagination.number) | ||
); | ||
} | ||
@@ -148,3 +172,3 @@ displaySetter($scope, output || filtered); | ||
*/ | ||
this.select = function select (row, mode) { | ||
this.select = function select(row, mode) { | ||
var rows = copyRefs(displayGetter($scope)); | ||
@@ -171,3 +195,3 @@ var index = rows.indexOf(row); | ||
*/ | ||
this.slice = function splice (start, number) { | ||
this.slice = function splice(start, number) { | ||
tableState.pagination.start = start; | ||
@@ -182,7 +206,7 @@ tableState.pagination.number = number; | ||
*/ | ||
this.tableState = function getTableState () { | ||
this.tableState = function getTableState() { | ||
return tableState; | ||
}; | ||
this.getFilteredCollection = function getFilteredCollection () { | ||
this.getFilteredCollection = function getFilteredCollection() { | ||
return filtered || safeCopy; | ||
@@ -195,3 +219,3 @@ }; | ||
*/ | ||
this.setFilterFunction = function setFilterFunction (filterName) { | ||
this.setFilterFunction = function setFilterFunction(filterName) { | ||
filter = $filter(filterName); | ||
@@ -204,3 +228,3 @@ }; | ||
*/ | ||
this.setSortFunction = function setSortFunction (sortFunctionName) { | ||
this.setSortFunction = function setSortFunction(sortFunctionName) { | ||
orderBy = $filter(sortFunctionName); | ||
@@ -213,21 +237,20 @@ }; | ||
*/ | ||
this.preventPipeOnWatch = function preventPipe () { | ||
this.preventPipeOnWatch = function preventPipe() { | ||
pipeAfterSafeCopy = false; | ||
}; | ||
}]) | ||
.directive('stTable', function () { | ||
return { | ||
restrict: 'A', | ||
controller: 'stTableController', | ||
link: function (scope, element, attr, ctrl) { | ||
} | ||
]).directive('stTable', function() { | ||
return { | ||
restrict: 'A', | ||
controller: 'stTableController', | ||
link: function(scope, element, attr, ctrl) { | ||
if (attr.stSetFilter) { | ||
ctrl.setFilterFunction(attr.stSetFilter); | ||
} | ||
if (attr.stSetFilter) { | ||
ctrl.setFilterFunction(attr.stSetFilter); | ||
} | ||
if (attr.stSetSort) { | ||
ctrl.setSortFunction(attr.stSetSort); | ||
} | ||
if (attr.stSetSort) { | ||
ctrl.setSortFunction(attr.stSetSort); | ||
} | ||
}; | ||
}); | ||
} | ||
}; | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
184431
74
14
21
1065
1