New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

angular-smart-table

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-smart-table - npm Package Compare versions

Comparing version 2.1.6 to 2.1.7

2

bower.json
{
"name": "angular-smart-table",
"version": "2.1.6",
"version": "2.1.7",
"homepage": "https://github.com/lorenzofox3/Smart-Table",

@@ -5,0 +5,0 @@ "authors": [

@@ -172,1 +172,5 @@ ## version 1.1.0

## version 2.1.7
* fix [#468](https://github.com/lorenzofox3/Smart-Table/issues/468) thanks to Douglas-Treadwell
/**
* @version 2.1.6
* @version 2.1.7
* @license MIT

@@ -34,2 +34,3 @@ */

descentClass: 'st-sort-descent',
descendingFirst: false,
skipNatural: false,

@@ -334,78 +335,84 @@ delay:300

ng.module('smart-table')
.directive('stSort', ['stConfig', '$parse', '$timeout', function (stConfig, $parse, $timeout) {
return {
restrict: 'A',
require: '^stTable',
link: function (scope, element, attr, ctrl) {
.directive('stSort', ['stConfig', '$parse', '$timeout', function (stConfig, $parse, $timeout) {
return {
restrict: 'A',
require: '^stTable',
link: function (scope, element, attr, ctrl) {
var predicate = attr.stSort;
var getter = $parse(predicate);
var index = 0;
var classAscent = attr.stClassAscent || stConfig.sort.ascentClass;
var classDescent = attr.stClassDescent || stConfig.sort.descentClass;
var stateClasses = [classAscent, classDescent];
var sortDefault;
var skipNatural = attr.stSkipNatural !== undefined ? attr.stSkipNatural : stConfig.sort.skipNatural;
var promise = null;
var throttle = attr.stDelay || stConfig.sort.delay;
var predicate = attr.stSort;
var getter = $parse(predicate);
var index = 0;
var classAscent = attr.stClassAscent || stConfig.sort.ascentClass;
var classDescent = attr.stClassDescent || stConfig.sort.descentClass;
var stateClasses = [classAscent, classDescent];
var sortDefault;
var skipNatural = attr.stSkipNatural !== undefined ? attr.stSkipNatural : stConfig.sort.skipNatural;
var descendingFirst = attr.stDescendingFirst !== undefined ? attr.stDescendingFirst : stConfig.sort.descendingFirst;
var promise = null;
var throttle = attr.stDelay || stConfig.sort.delay;
if (attr.stSortDefault) {
sortDefault = scope.$eval(attr.stSortDefault) !== undefined ? scope.$eval(attr.stSortDefault) : attr.stSortDefault;
}
if (attr.stSortDefault) {
sortDefault = scope.$eval(attr.stSortDefault) !== undefined ? scope.$eval(attr.stSortDefault) : attr.stSortDefault;
}
//view --> table state
function sort () {
index++;
var func;
predicate = ng.isFunction(getter(scope)) || ng.isArray(getter(scope)) ? getter(scope) : attr.stSort;
if (index % 3 === 0 && !!skipNatural !== true) {
//manual reset
index = 0;
ctrl.tableState().sort = {};
ctrl.tableState().pagination.start = 0;
func = ctrl.pipe.bind(ctrl);
} else {
func = ctrl.sortBy.bind(ctrl, predicate, index % 2 === 0);
}
if (promise !== null) {
$timeout.cancel(promise);
}
if (throttle < 0) {
func();
} else {
promise = $timeout(func, throttle);
}
}
//view --> table state
function sort () {
if (descendingFirst) {
index = index === 0 ? 2 : index - 1;
} else {
index++;
}
element.bind('click', function sortClick () {
if (predicate) {
scope.$apply(sort);
}
});
var func;
predicate = ng.isFunction(getter(scope)) || ng.isArray(getter(scope)) ? getter(scope) : attr.stSort;
if (index % 3 === 0 && !!skipNatural !== true) {
//manual reset
index = 0;
ctrl.tableState().sort = {};
ctrl.tableState().pagination.start = 0;
func = ctrl.pipe.bind(ctrl);
} else {
func = ctrl.sortBy.bind(ctrl, predicate, index % 2 === 0);
}
if (promise !== null) {
$timeout.cancel(promise);
}
if (throttle < 0) {
func();
} else {
promise = $timeout(func, throttle);
}
}
if (sortDefault) {
index = sortDefault === 'reverse' ? 1 : 0;
sort();
}
element.bind('click', function sortClick () {
if (predicate) {
scope.$apply(sort);
}
});
//table state --> view
scope.$watch(function () {
return ctrl.tableState().sort;
}, function (newValue) {
if (newValue.predicate !== predicate) {
index = 0;
element
.removeClass(classAscent)
.removeClass(classDescent);
} else {
index = newValue.reverse === true ? 2 : 1;
element
.removeClass(stateClasses[index % 2])
.addClass(stateClasses[index - 1]);
}
}, true);
}
};
}]);
if (sortDefault) {
index = sortDefault === 'reverse' ? 1 : 0;
sort();
}
//table state --> view
scope.$watch(function () {
return ctrl.tableState().sort;
}, function (newValue) {
if (newValue.predicate !== predicate) {
index = 0;
element
.removeClass(classAscent)
.removeClass(classDescent);
} else {
index = newValue.reverse === true ? 2 : 1;
element
.removeClass(stateClasses[index % 2])
.addClass(stateClasses[index - 1]);
}
}, true);
}
};
}]);
ng.module('smart-table')

@@ -412,0 +419,0 @@ .directive('stPagination', ['stConfig', function (stConfig) {

/**
* @version 2.1.6
* @version 2.1.7
* @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 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",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)),S===!0&&v.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,f=n(g),d=f.assign,m=s("orderBy"),h=s("filter"),b=r(f(a)),P={sort:{},search:{},pagination:{start:0,totalItemCount:0}},S=!0,v=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))),d(a,t||u)},this.select=function(t,n){var s=r(f(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(){S=!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(){f++;var e;p=t.isFunction(g(i))||t.isArray(g(i))?g(i):l.stSort,f%3===0&&!!b!=!0?(f=0,c.tableState().sort={},c.tableState().pagination.start=0,e=c.pipe.bind(c)):e=c.sortBy.bind(c,p,f%2===0),null!==P&&s.cancel(P),0>S?e():P=s(e,S)}var u,p=l.stSort,g=n(p),f=0,d=l.stClassAscent||a.sort.ascentClass,m=l.stClassDescent||a.sort.descentClass,h=[d,m],b=l.stSkipNatural!==e?l.stSkipNatural:a.sort.skipNatural,P=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&&(f="reverse"===u?1:0,o()),i.$watch(function(){return c.tableState().sort},function(t){t.predicate!==p?(f=0,r.removeClass(d).removeClass(m)):(f=t.reverse===!0?2:1,r.removeClass(h[f%2]).addClass(h[f-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 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)),S===!0&&v.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}},S=!0,v=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(){S=!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!==S&&s.cancel(S),0>v?e():S=s(e,v)}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,S=null,v=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);
//# sourceMappingURL=smart-table.min.js.map
{
"name": "angular-smart-table",
"version": "2.1.6",
"version": "2.1.7",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -19,2 +19,3 @@ ng.module('smart-table')

descentClass: 'st-sort-descent',
descendingFirst: false,
skipNatural: false,

@@ -21,0 +22,0 @@ delay:300

ng.module('smart-table')
.directive('stSort', ['stConfig', '$parse', '$timeout', function (stConfig, $parse, $timeout) {
return {
restrict: 'A',
require: '^stTable',
link: function (scope, element, attr, ctrl) {
.directive('stSort', ['stConfig', '$parse', '$timeout', function (stConfig, $parse, $timeout) {
return {
restrict: 'A',
require: '^stTable',
link: function (scope, element, attr, ctrl) {
var predicate = attr.stSort;
var getter = $parse(predicate);
var index = 0;
var classAscent = attr.stClassAscent || stConfig.sort.ascentClass;
var classDescent = attr.stClassDescent || stConfig.sort.descentClass;
var stateClasses = [classAscent, classDescent];
var sortDefault;
var skipNatural = attr.stSkipNatural !== undefined ? attr.stSkipNatural : stConfig.sort.skipNatural;
var promise = null;
var throttle = attr.stDelay || stConfig.sort.delay;
var predicate = attr.stSort;
var getter = $parse(predicate);
var index = 0;
var classAscent = attr.stClassAscent || stConfig.sort.ascentClass;
var classDescent = attr.stClassDescent || stConfig.sort.descentClass;
var stateClasses = [classAscent, classDescent];
var sortDefault;
var skipNatural = attr.stSkipNatural !== undefined ? attr.stSkipNatural : stConfig.sort.skipNatural;
var descendingFirst = attr.stDescendingFirst !== undefined ? attr.stDescendingFirst : stConfig.sort.descendingFirst;
var promise = null;
var throttle = attr.stDelay || stConfig.sort.delay;
if (attr.stSortDefault) {
sortDefault = scope.$eval(attr.stSortDefault) !== undefined ? scope.$eval(attr.stSortDefault) : attr.stSortDefault;
}
if (attr.stSortDefault) {
sortDefault = scope.$eval(attr.stSortDefault) !== undefined ? scope.$eval(attr.stSortDefault) : attr.stSortDefault;
}
//view --> table state
function sort () {
index++;
var func;
predicate = ng.isFunction(getter(scope)) || ng.isArray(getter(scope)) ? getter(scope) : attr.stSort;
if (index % 3 === 0 && !!skipNatural !== true) {
//manual reset
index = 0;
ctrl.tableState().sort = {};
ctrl.tableState().pagination.start = 0;
func = ctrl.pipe.bind(ctrl);
} else {
func = ctrl.sortBy.bind(ctrl, predicate, index % 2 === 0);
}
if (promise !== null) {
$timeout.cancel(promise);
}
if (throttle < 0) {
func();
} else {
promise = $timeout(func, throttle);
}
}
//view --> table state
function sort () {
if (descendingFirst) {
index = index === 0 ? 2 : index - 1;
} else {
index++;
}
element.bind('click', function sortClick () {
if (predicate) {
scope.$apply(sort);
}
});
var func;
predicate = ng.isFunction(getter(scope)) || ng.isArray(getter(scope)) ? getter(scope) : attr.stSort;
if (index % 3 === 0 && !!skipNatural !== true) {
//manual reset
index = 0;
ctrl.tableState().sort = {};
ctrl.tableState().pagination.start = 0;
func = ctrl.pipe.bind(ctrl);
} else {
func = ctrl.sortBy.bind(ctrl, predicate, index % 2 === 0);
}
if (promise !== null) {
$timeout.cancel(promise);
}
if (throttle < 0) {
func();
} else {
promise = $timeout(func, throttle);
}
}
if (sortDefault) {
index = sortDefault === 'reverse' ? 1 : 0;
sort();
}
element.bind('click', function sortClick () {
if (predicate) {
scope.$apply(sort);
}
});
//table state --> view
scope.$watch(function () {
return ctrl.tableState().sort;
}, function (newValue) {
if (newValue.predicate !== predicate) {
index = 0;
element
.removeClass(classAscent)
.removeClass(classDescent);
} else {
index = newValue.reverse === true ? 2 : 1;
element
.removeClass(stateClasses[index % 2])
.addClass(stateClasses[index - 1]);
}
}, true);
}
};
}]);
if (sortDefault) {
index = sortDefault === 'reverse' ? 1 : 0;
sort();
}
//table state --> view
scope.$watch(function () {
return ctrl.tableState().sort;
}, function (newValue) {
if (newValue.predicate !== predicate) {
index = 0;
element
.removeClass(classAscent)
.removeClass(classDescent);
} else {
index = newValue.reverse === true ? 2 : 1;
element
.removeClass(stateClasses[index % 2])
.addClass(stateClasses[index - 1]);
}
}, true);
}
};
}]);

@@ -435,2 +435,166 @@ describe('stSort Directive', function () {

it('should sort by clicked header in descending order first (by default) when requested', inject(function ($timeout, $compile, stConfig) {
var template = '<table dummy="" st-table="rowCollection">' +
'<thead>' +
'<tr><th st-sort="name">name</th>' +
'<th st-sort="firstname">firstname</th>' +
'<th st-sort="getters.age">age</th>' +
'<th st-sort="getters.name">age</th>' +
'</tr>' +
'</thead>' +
'<tbody>' +
'<tr class="test-row" ng-repeat="row in rowCollection">' +
'<td>{{row.name}}</td>' +
'<td>{{row.firstname}}</td>' +
'<td>{{row.age}}</td>' +
'</tr>' +
'</tbody>' +
'</table>';
stConfig.sort.descendingFirst = 'true'; // or any defined value
element = $compile(template)(scope);
scope.$apply();
var ths = element.find('th');
var actual;
angular.element(ths[1]).triggerHandler('click');
$timeout.flush();
actual = trToModel(element.find('tr.test-row'));
expect(hasClass(ths[1], 'st-sort-ascent')).toBe(false);
expect(hasClass(ths[1], 'st-sort-descent')).toBe(true);
expect(actual).toEqual([
{name: 'Renard', firstname: 'Olivier', age: 33},
{name: 'Renard', firstname: 'Laurent', age: 66},
{name: 'Francoise', firstname: 'Frere', age: 99},
{name: 'Leponge', firstname: 'Bob', age: 22},
{name: 'Faivre', firstname: 'Blandine', age: 44}
]);
}));
it('should sort by clicked header in descending order first when requested', inject(function ($timeout, $compile) {
var template = '<table dummy="" st-table="rowCollection">' +
'<thead>' +
'<tr><th st-sort="name">name</th>' +
'<th st-sort="firstname" st-descending-first="true">firstname</th>' +
'<th st-sort="getters.age">age</th>' +
'<th st-sort="getters.name">age</th>' +
'</tr>' +
'</thead>' +
'<tbody>' +
'<tr class="test-row" ng-repeat="row in rowCollection">' +
'<td>{{row.name}}</td>' +
'<td>{{row.firstname}}</td>' +
'<td>{{row.age}}</td>' +
'</tr>' +
'</tbody>' +
'</table>';
element = $compile(template)(scope);
scope.$apply();
var ths = element.find('th');
var actual;
angular.element(ths[1]).triggerHandler('click');
$timeout.flush();
actual = trToModel(element.find('tr.test-row'));
expect(hasClass(ths[1], 'st-sort-ascent')).toBe(false);
expect(hasClass(ths[1], 'st-sort-descent')).toBe(true);
expect(actual).toEqual([
{name: 'Renard', firstname: 'Olivier', age: 33},
{name: 'Renard', firstname: 'Laurent', age: 66},
{name: 'Francoise', firstname: 'Frere', age: 99},
{name: 'Leponge', firstname: 'Bob', age: 22},
{name: 'Faivre', firstname: 'Blandine', age: 44}
]);
}));
it('should switch to ascending order on the second click', inject(function ($timeout, $compile) {
var template = '<table dummy="" st-table="rowCollection">' +
'<thead>' +
'<tr><th st-sort="name">name</th>' +
'<th st-sort="firstname" st-descending-first="true">firstname</th>' +
'<th st-sort="getters.age">age</th>' +
'<th st-sort="getters.name">age</th>' +
'</tr>' +
'</thead>' +
'<tbody>' +
'<tr class="test-row" ng-repeat="row in rowCollection">' +
'<td>{{row.name}}</td>' +
'<td>{{row.firstname}}</td>' +
'<td>{{row.age}}</td>' +
'</tr>' +
'</tbody>' +
'</table>';
element = $compile(template)(scope);
scope.$apply();
var ths = element.find('th');
var actual;
angular.element(ths[1]).triggerHandler('click');
$timeout.flush();
angular.element(ths[1]).triggerHandler('click');
$timeout.flush();
actual = trToModel(element.find('tr.test-row'));
expect(hasClass(ths[1], 'st-sort-ascent')).toBe(true);
expect(hasClass(ths[1], 'st-sort-descent')).toBe(false);
expect(actual).toEqual([
{name: 'Faivre', firstname: 'Blandine', age: 44},
{name: 'Leponge', firstname: 'Bob', age: 22},
{name: 'Francoise', firstname: 'Frere', age: 99},
{name: 'Renard', firstname: 'Laurent', age: 66},
{name: 'Renard', firstname: 'Olivier', age: 33}
]);
}));
it('should reset the sort state on the third call regardless of st-desending-first', inject(function ($timeout, $compile) {
var template = '<table dummy="" st-table="rowCollection">' +
'<thead>' +
'<tr><th st-sort="name">name</th>' +
'<th st-sort="firstname" st-descending-first="true">firstname</th>' +
'<th st-sort="getters.age">age</th>' +
'<th st-sort="getters.name">age</th>' +
'</tr>' +
'</thead>' +
'<tbody>' +
'<tr class="test-row" ng-repeat="row in rowCollection">' +
'<td>{{row.name}}</td>' +
'<td>{{row.firstname}}</td>' +
'<td>{{row.age}}</td>' +
'</tr>' +
'</tbody>' +
'</table>';
element = $compile(template)(scope);
scope.$apply();
var ths = element.find('th');
var actual;
angular.element(ths[1]).triggerHandler('click');
$timeout.flush();
angular.element(ths[1]).triggerHandler('click');
$timeout.flush();
tableState.sort = {
predicate: 'firstname',
reverse: true
};
tableState.pagination.start = 40;
angular.element(ths[1]).triggerHandler('click');
$timeout.flush();
actual = trToModel(element.find('tr.test-row'));
expect(hasClass(ths[1], 'st-sort-ascent')).toBe(false);
expect(hasClass(ths[1], 'st-sort-descent')).toBe(false);
expect(actual).toEqual([
{name: 'Renard', firstname: 'Laurent', age: 66},
{name: 'Francoise', firstname: 'Frere', age: 99},
{name: 'Renard', firstname: 'Olivier', age: 33},
{name: 'Leponge', firstname: 'Bob', age: 22},
{name: 'Faivre', firstname: 'Blandine', age: 44}
]);
expect(tableState.sort).toEqual({});
expect(tableState.pagination.start).toEqual(0);
}));
});

@@ -437,0 +601,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc