Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Date filter is ignored
Message
From
30/05/2015 03:41:39
 
General information
Forum:
Javascript
Category:
Other
Miscellaneous
Thread ID:
01620266
Message ID:
01620381
Views:
46
This message has been marked as a message which has helped to the initial question of the thread.
Likes (1)
>I don't want to have filter on ng-repeat anymore, I'd like to apply filter by pressing a button.
>
>Do you mean my applyFilter procedure is too complex now?
>

Just thinking it could be simpler. You could create a date range filter which would create a new array of valid dates for the input array rather then removing unwanted elements (several examples online e.g; http://stackoverflow.com/questions/25515431/ng-repeat-filtering-data-by-date-range). You could then pipe .filteredTransactions to that filter.

Advantages : You have a generic date range filter that could be used elsewhere and cleaner code to replace the below.
And since the original .filteredTransactions would not be modified by the date range logic you could, in circumstances where only the date range has changed, avoid rebuilding that array.

Depends on your circumstances - might not be worth the candle........


>>>>See my reply to your other thread.....
>>>
>>>Trying to figure out syntax here:
>>>
>>>
>>>if ($scope.searchTerm.message)
>>>                    {
>>>                        $scope.filteredTransactions = $filter('filter')($scope.invoiceTransactionsObject.transactions, { message: $scope.searchTerm.message, item: $scope.searchTerm.message });
>>>                    }
>>>
>>>I need a match in either of these 2 properties, not in all of them.
>>>
>>>UPDATE. I figured out (based on stackoverflow thread) that first problem, but now I am having a bug in my dates logic and can not figure out what is wrong. Can you help? It looks like the second condition with the endDate is not working:
>>>
>>>
>>> $scope.applyFilter = function()
>>>                {
>>>                    $scope.filteredTransactions = $scope.invoiceTransactionsObject.transactions;
>>>                    if ($scope.searchTerm.message)
>>>                    {
>>>                        $scope.filteredTransactions = $filter('filter')($scope.invoiceTransactionsObject.transactions, ({ message: $scope.searchTerm.message } || { item: $scope.searchTerm.message }));
>>>                    }
>>>
>>>                    if ($scope.startDate != null || $scope.endDate != null)
>>>                    {
>>>                        for (var i = $scope.filteredTransactions.length - 1; 0, i--;)
>>>                        {
>>>                            if ($scope.startDate!=null && $scope.filteredTransactions[i].dateTime < $scope.startDate)
>>>                            {
>>>                                $scope.filteredTransactions.splice(i,1); // remove that element
>>>                                continue;
>>>                            }
>>>                            if ($scope.endDate!=null && $scope.filteredTransactions[i].dateTime > $scope.endDate)
>>>                            {
>>>                                $scope.filteredTransactions.splice(i,1); // remove that element
>>>                                continue;
>>>                            }
>>>                        }
>>>                    }
>>>                    $scope.filteredTotal = $scope.getTotal($scope.filteredTransactions, 'extension');
>>>                }
>>>
>>>
>>>UPDATE2. I think I know the problem, testing now.
>>>
>>>UPDATE3. Solved the problem.
>>
>>Looks overly complicated. Why not something like :
>>http://stackoverflow.com/questions/21411686/how-to-filter-multiple-values-or-operation-in-angularjs-with-checkbox
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform