Recently, I have developed a custom function to determine the "fromNow" value using Moment and now I am looking to organize the data based on this function's output.
I aim to place the Table Element at the top where the Days from Now are fewer.
In the table below, the entry for 31 Days From Today in the 2nd column is lower, and I want to prioritize this element. However, my attempts so far have been unsuccessful.
Could someone assist me with this sorting task? Table
Utilizing AngularJS OrderBy:
<tr ng-repeat="x in Holidays|orderBy:findFromNow">
<td>{{$index+1}}</td>
<td>{{x.Day}}</td>
<td>
<span class="label label-warning">{{findFromNow(x.Date)}} Days From Today</span></td>
</tr>
Custom Function:
$scope.findFromNow = function (inputDate) {
var m = moment(inputDate, "D-MMM-YY");
var today = moment().startOf('day');
var days = Math.round((today - m) / 86400000);
if (days > 0) {
return 999;
} else {
return (days * (-1));
}
}
Holidays JSON:
[
{
"Day": "Monday",
"Date": "2-Jan-17"
},
{
"Day": "Monday",
"Date": "20-Feb-17"
},
{
"Day": "Monday",
"Date": "29-May-17"
},
{
"Day": "Monday",
"Date": "3-Jul-17"
},
{
"Day": "Tuesday",
"Date": "4-Jul-17"
},
{
"Day": "Monday",
"Date": "4-Sep-17"
},
{
"Day": "Thursday",
"Date": "23-Nov-17"
},
{
"Day": "Friday",
"Date": "24-Nov-17"
},
{
"Day": "Monday",
"Date": "25-Dec-17"
}
]