when I click on a column header, sorting happens as expected while keeping null values at the bottom for both ascending and descending cases. It is working this way for all my columns except for the ones with date values where all null values are being placed on the top or bottom. Is this expected with AngularJS or am I doing something wrong?
Here is my JS code for sorting that is called using ng-click on a column header:
$scope.Data = $scope.Data.sort(function (a, b)
{
var firstValue = getDisplayValue(a, $scope.TableSorting.SortedByColumn);
var secondValue = getDisplayValue(b, $scope.TableSorting.SortedByColumn);
if (firstValue === null)
{
return 1;
}
else if (secondValue === null)
{
return -1;
}
if (isDate(firstValue) && isDate(secondValue))
{
firstValue = new Date(firstValue);
secondValue = new Date(secondValue);
}
if (typeof firstValue === 'string' && typeof secondValue === 'string')
{
firstValue = firstValue.toLowerCase();
secondValue = secondValue.toLowerCase();
}
if (firstValue < secondValue)
{
return $scope.TableSorting.SortInReverseOrder ? 1 : -1;
}
if (firstValue > secondValue)
{
return $scope.TableSorting.SortInReverseOrder ? -1 : 1;
}
return 0;
});
};
getDisplayValue = function (data, columnName) {
if (columnName == 'PreviousCallIsInbound')
{
return data.PreviousConferenceId ? (data.PreviousCallDate ? 'Yes' : 'No') : null;
}
if (columnName == 'NextCallIsInbound') {
return data.NextConferenceId ? (data.NextCallDate ? 'Yes' : 'No') : null;
}
return data[columnName];
};
I tried including checks for undefined.
Any help is appreciated!