0
$scope.Data = [
{
    "title": "Algolia's Global Roadshow",
    "author": "Ryan Chen",
    "excerpt": "We've heard it from experts, industry surveys, and our most successful customers: search and discovery are key to moving the digital conversation forward.",
    "date": "2018-10-17",
    "date_timestamp": 1539734400
  },
  {
    "title": "Black Friday & Site Search: small tips, big difference",
    "author": "Matthieu Blandineau",
    "excerpt": "It’s no surprise that during the holiday season, Black Friday & Cyber Monday are absolutely critical events for any e-commerce business. According to Adobe, online retailers earned $108.15B between Nov 1 and Dec 31 2017, up 13.8% from 2016. Only in the U.S.",
    "date": "2018-10-05",
    "date_timestamp": 1538697600
  },
  {
    "title": "For better school projects, a partnership with GitHub",
    "author": "Jessica West",
    "excerpt": "Hello GitHubbers and Algolians alike! We have some exciting news we’d like to share with you. Algolia is so pleased to announce that we have partnered with GitHub’s Student Developer Pack to help students build search functionality into their projects freely and effortlessly 🎉.",
    "date": "2018-09-18",
    "date_timestamp": 1537228800
  }
]

I have 3 Anchor Button ( Today , Week , Month ) I want to Filter this data using ng-cick = GetDate(Today or Week or Month) and Bind the data

How to filter the $scope.Data based on what i click ( Today , Week and Month )

Please help

1 Answer 1

1

For filtering the data you can do something along the lines of:

// Set the start and end dates for the search. Limit to one day, week, etc.
const startDate = new Date(2018, 9, 4);
const endDate = new Date(2018, 9, 6);

// Filter by comparing the dates
const filteredData = $scope.Data.filter(e => {
    const date = new Date(e.date);
    return date.getTime() >= startDate.getTime() && date.getTime() <= endDate.getTime();
});

console.log(filteredData);

And bind as applicable to the button clicks.

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.