1

i have a problems with my filter date , I would like to filter between 2 date but with a condition if the date from is not valid then I start at 2017-01-01 (for that I think it is good) and if the date 'to' is not valid I start Has the current date

Here is my plunker:

http://plnkr.co/edit/8sK29zG7YoPOdntbFfcK?p=preview

Thank you for your help

1
  • Post the relevant code in your question, tell what it's supposed to do and what it does instead. Commented Mar 19, 2017 at 12:53

2 Answers 2

1

Your filter could be something like this :

app.filter("myfilter", function($filter) {

      return function(items, from, to) {

      const testFrom = Date.parse(from);
      const testTo = Date.parse(to);      


      if (!testFrom){
        console.log('Not valid');
        from = moment('2017-01-01');
      }

      //here it does nt work
      if (!testTo){
       to = moment();              
      }      


      const valids = items.reduce((acc,val) => {
         const date = moment(val.dateenvoi);
         if(date.isSameOrAfter(from) && date.isSameOrBefore(to))
          acc.push(val)        
        return acc;
      },[]);      
      return valids;      
      };
});
Sign up to request clarification or add additional context in comments.

Comments

0

Check this

No need for custom filter for this functionality, you can use angular predefined filter for this like

<input type="text" name="S_Date" ng-model="filter.dateenvoi"/>

and

<tr ng-repeat="x in myData | filter: filter">

working Plunker

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.