From bfaf87bbcc0e8b97dd7d82967f65add4f997ebd2 Mon Sep 17 00:00:00 2001 From: Stephen Knox Date: Wed, 31 Aug 2016 11:15:48 +0100 Subject: [PATCH 1/3] Add functionality for custom sort --- src/scripts/mdColumn.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/scripts/mdColumn.js b/src/scripts/mdColumn.js index f693dcda..36688faa 100644 --- a/src/scripts/mdColumn.js +++ b/src/scripts/mdColumn.js @@ -48,6 +48,10 @@ function mdColumn($compile, $mdUtil) { function isActive() { return scope.orderBy && (headCtrl.order === scope.orderBy || headCtrl.order === '-' + scope.orderBy); } + + function hasCustomSortFunc() { + return scope.customSortFunc; + } function isNumeric() { return attrs.mdNumeric === '' || scope.numeric; @@ -56,9 +60,17 @@ function mdColumn($compile, $mdUtil) { function setOrder() { scope.$applyAsync(function () { if(isActive()) { + if (hasCustomSortFunc()) { + headCtrl.order = scope.customSortFunc; + } else { headCtrl.order = scope.getDirection() === 'md-asc' ? '-' + scope.orderBy : scope.orderBy; + } } else { + if (hasCustomSortFunc()) { + headCtrl.order = scope.customSortFunc; + } else { headCtrl.order = scope.getDirection() === 'md-asc' ? scope.orderBy : '-' + scope.orderBy; + } } if(angular.isFunction(headCtrl.onReorder)) { @@ -121,8 +133,9 @@ function mdColumn($compile, $mdUtil) { scope: { numeric: '=?mdNumeric', orderBy: '@?mdOrderBy' + customSortFunc: '=?customSort' } }; } -mdColumn.$inject = ['$compile', '$mdUtil']; \ No newline at end of file +mdColumn.$inject = ['$compile', '$mdUtil']; From c72f1b01c54249823515b9dbdd144c22c76d82ce Mon Sep 17 00:00:00 2001 From: Stephen Knox Date: Wed, 31 Aug 2016 11:20:20 +0100 Subject: [PATCH 2/3] Update readme for custom sort --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index cb0abef7..ed899648 100644 --- a/README.md +++ b/README.md @@ -163,9 +163,12 @@ angular.module('demoApp').controller('sampleController', ['$nutrition', '$scope' | `mdOnReorder` | `mdHead` | `function` | A callback function for when the order changes. The callback will receive the new order. | | `mdOrder` | `mdHead` | `string` | A variable to bind the sort order to. | | `mdOrderBy` | `mdColumn` | `string` | The value to bind to the sort order. | +| `mdCustomSort` | `mdColumn` | `string` | The custom function which translates data into values which can be ordered | When the user clicks the `md-column` element, the value of the `md-order-by` attribute will be bound to the variable provided to the `md-order` attribute on the `md-head` element. If the column is already sorted by that value, a minus sign `-` will be prefixed to the value. For most query languages, this is the universal symbol to sort descending. +If the `md-custom-sort` element is used, the value of the `md-order-by` attribute will be bound to the function provided to `md-custom-sort`which will translate raw values to orderable values + The variable can be used to send a query to the server or as the `orderBy` property of an `ng-repeat` expression. **Example Using ngRepeat** From e2cb60ddccb8e1885f33041fa8fe781423c1f156 Mon Sep 17 00:00:00 2001 From: Stephen Knox Date: Wed, 31 Aug 2016 11:24:49 +0100 Subject: [PATCH 3/3] Fix directive scope variable name --- src/scripts/mdColumn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/mdColumn.js b/src/scripts/mdColumn.js index 36688faa..cf260f18 100644 --- a/src/scripts/mdColumn.js +++ b/src/scripts/mdColumn.js @@ -133,7 +133,7 @@ function mdColumn($compile, $mdUtil) { scope: { numeric: '=?mdNumeric', orderBy: '@?mdOrderBy' - customSortFunc: '=?customSort' + customSortFunc: '=?mdCustomSort' } }; }