I'm new to Angularjs and I could use some assistance with sorting dates in milliseconds in descending order, as well as implementing a filter for the table columns. I've set up a plunker example, but when I enter a filter parameter, the data doesn't seem to be filtered properly, and it disappears from the table.
Can someone help me with sorting the date column and setting up a case-insensitive filter search? Below is the code I am currently using:
<table ng-table="tableParams" show-filter="true" class="table">
<tr ng-repeat="item in $data" height="10px">
<td data-title="'Date'" filter="{ 'item[0]': 'date' }" sortable="'item[0]'">{{translate(item[0])}}</td>
<td data-title="'Count'" filter="{ 'item[1]': 'text' }" sortable="'item[1]'">{{item[1]}}</td>
</tr>
</table>
$scope.translate = function(value) {
if (value == null || value == undefined)
return value;
var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
var myDate = new Date( value );
return myDate.getDate() + " " + monthNames[myDate.getMonth()] + " "+myDate.getFullYear();
}
$scope.tableParams = new ngTableParams({
page: 1,
count: 10
}, {
total: $scope.tasksRunDataForTable.length,
getData: function($defer, params) {
var sortedData = params.sorting() ?
$filter('orderBy')($scope.tasksRunDataForTable, params.orderBy()) :
$scope.tasksRunDataForTable;
var orderedData = params.filter() ?
$filter('filter')(sortedData, params.filter()) :
sortedData;
params.total(orderedData.length);
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
Update
I managed to get the filter working for the count column, but I'm still struggling with filtering dates and sorting on both columns. Here's the link to the updated plunker.
<td data-title="'Count'" filter="{ '1': 'text' }" sortable="'1'">{{item[1]}}</td>