0

I created a working filter that filters the data by month.

A click on a month name shows correct data. I wonder how to show all data on page load. Actually, no data is shown on page load until I click a select a month.

PlasmaCrm.filter('triParMois', function() {
  return function( items, mois ) {
    var filtered = [];
    angular.forEach(items, function(item) {
      if(item.created_at.substring(5, 7) == mois) {
        filtered.push(item);
      }
    });
    return filtered;
  };
});

I use this filter there:

<tr ng-repeat="finance in finances | triParMois:leMois">

And I set the value of leMois with a click on the motn name like this

<button ng-click="leMois = 01 ">Janvier</button >

How should I do?

1 Answer 1

1

If leMois is undefined at start you could do somthing like this:

PlasmaCrm.filter('triParMois', function() {
  return function( items, mois ) {
    var filtered = [];
    angular.forEach(items, function(item) {
      if(item.created_at.substring(5, 7) == mois || angular.isUndefined(mois)) {
        filtered.push(item);
      }
    });
    return filtered;
  };
});

If it is null or some other value check for that instead.

Sign up to request clarification or add additional context in comments.

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.