Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzofox3 committed Mar 10, 2015
1 parent 0f05674 commit 5b5e0dd
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 144 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-smart-table",
"version": "1.4.12",
"version": "1.4.13",
"homepage": "https://github.com/lorenzofox3/Smart-Table",
"authors": [
"lorenzofox3 <[email protected]>"
Expand Down
5 changes: 5 additions & 0 deletions changeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,8 @@ function(tableState, tableController){
* don't use pagination class twice
* build improvement

## version 1.4.13

* use a global configuration
* expose filtered collection result

185 changes: 105 additions & 80 deletions dist/smart-table.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/smart-table.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-smart-table",
"version": "1.4.12",
"version": "1.4.13",
"description": "",
"main": "dist/smart-table.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/stPagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ng.module('smart-table')
scope.currentPage = 1;
scope.pages = [];

function redraw() {
function redraw () {
var paginationState = ctrl.tableState().pagination;
var start = 1;
var end;
Expand All @@ -45,7 +45,7 @@ ng.module('smart-table')
scope.pages.push(i);
}

if (prevPage!==scope.currentPage) {
if (prevPage !== scope.currentPage) {
scope.stPageChange({newPage: scope.currentPage});
}
}
Expand All @@ -71,7 +71,7 @@ ng.module('smart-table')
}
};

if(!ctrl.tableState().pagination.number){
if (!ctrl.tableState().pagination.number) {
ctrl.slice(0, scope.stItemsByPage);
}
}
Expand Down
78 changes: 39 additions & 39 deletions src/stSearch.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
ng.module('smart-table')
.directive('stSearch', ['stConfig', '$timeout', function (stConfig, $timeout) {
return {
require: '^stTable',
scope: {
predicate: '=?stSearch'
},
link: function (scope, element, attr, ctrl) {
var tableCtrl = ctrl;
var promise = null;
var throttle = attr.stDelay || stConfig.search.delay;
.directive('stSearch', ['stConfig', '$timeout', function (stConfig, $timeout) {
return {
require: '^stTable',
scope: {
predicate: '=?stSearch'
},
link: function (scope, element, attr, ctrl) {
var tableCtrl = ctrl;
var promise = null;
var throttle = attr.stDelay || stConfig.search.delay;

scope.$watch('predicate', function (newValue, oldValue) {
if (newValue !== oldValue) {
ctrl.tableState().search = {};
tableCtrl.search(element[0].value || '', newValue);
}
});
scope.$watch('predicate', function (newValue, oldValue) {
if (newValue !== oldValue) {
ctrl.tableState().search = {};
tableCtrl.search(element[0].value || '', newValue);
}
});

//table state -> view
scope.$watch(function () {
return ctrl.tableState().search;
}, function (newValue, oldValue) {
var predicateExpression = scope.predicate || '$';
if (newValue.predicateObject && newValue.predicateObject[predicateExpression] !== element[0].value) {
element[0].value = newValue.predicateObject[predicateExpression] || '';
}
}, true);
//table state -> view
scope.$watch(function () {
return ctrl.tableState().search;
}, function (newValue, oldValue) {
var predicateExpression = scope.predicate || '$';
if (newValue.predicateObject && newValue.predicateObject[predicateExpression] !== element[0].value) {
element[0].value = newValue.predicateObject[predicateExpression] || '';
}
}, true);

// view -> table state
element.bind('input', function (evt) {
evt = evt.originalEvent || evt;
if (promise !== null) {
$timeout.cancel(promise);
}
promise = $timeout(function () {
tableCtrl.search(evt.target.value, scope.predicate || '');
promise = null;
}, throttle);
});
}
};
}]);
// view -> table state
element.bind('input', function (evt) {
evt = evt.originalEvent || evt;
if (promise !== null) {
$timeout.cancel(promise);
}
promise = $timeout(function () {
tableCtrl.search(evt.target.value, scope.predicate || '');
promise = null;
}, throttle);
});
}
};
}]);
6 changes: 3 additions & 3 deletions src/stSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ ng.module('smart-table')
var sortDefault;

if (attr.stSortDefault) {
sortDefault = scope.$eval(attr.stSortDefault) !== undefined ? scope.$eval(attr.stSortDefault) : attr.stSortDefault;
sortDefault = scope.$eval(attr.stSortDefault) !== undefined ? scope.$eval(attr.stSortDefault) : attr.stSortDefault;
}

//view --> table state
function sort() {
function sort () {
index++;
predicate = ng.isFunction(getter(scope)) ? getter(scope) : attr.stSort;
if (index % 3 === 0 && attr.stSkipNatural === undefined) {
Expand All @@ -32,7 +32,7 @@ ng.module('smart-table')
}
}

element.bind('click', function sortClick() {
element.bind('click', function sortClick () {
if (predicate) {
scope.$apply(sort);
}
Expand Down
Loading

0 comments on commit 5b5e0dd

Please sign in to comment.