Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

vue date filter component

new Vue({
  el: '#app',
  data: {
    selectedType: '',
    startDate:null,
    endDate:null,
    items: [
      {
        name: 'Nolan',
        type: 'mercedes',
        year: '2020',
        country: 'england',
        date: '08/01/2020'
      },
      {
        name: 'Edgar',
        type: 'bmw',
        year: '2020',
        country:'belgium',
        date: '08/11/2020'
      },
      {
        name: 'John',
        type: 'bmw',
        year: '2019',
        country: 'england',
        date: '08/21/2020'
      },
      {
        name: 'Axel',
        type: 'mercedes',
        year: '2020',
        country: 'england',
        date: '08/01/2020'
      }
    ]
  },
  computed: {
    filterItem() {
      let filterType = this.selectedType;
      let startDate = this.localizeDate(this.startDate);
      let endDate = this.localizeDate(this.endDate);
      
      const itemsByType = filterType ? this.items.filter(item => item.type === filterType) : this.items
      return itemsByType
        .filter(item => {
          const itemDate = new Date(item.date)
          if (startDate && endDate) {
            return startDate <= itemDate && itemDate <= endDate;
          }
          if (startDate && !endDate) {
            return startDate <= itemDate;
          }
          if (!startDate && endDate) {
            return itemDate <= endDate;
          }
          return true;
        })
    }
  },
  methods: {
    localizeDate(date) {
      // Date picker uses ISO format (yyyy-mm-dd), which is UTC. The data
      // contains locale specific date strings (mm/dd/yyyy), which `Date`
      // parses with local time-zone offset instead of UTC. Normalize the
      // ISO date so we're comparing local times.
      if (!date || !date.includes('-')) return date
      const [yyyy, mm, dd] = date.split('-')
      return new Date(`${mm}/${dd}/${yyyy}`)
    },
    formatDate(date) {
      return new Intl.DateTimeFormat('en-US', { dateStyle: 'long' }).format(new Date(date))
    }
  }
})
Comment

vuejs filter array by dates

<ul id="sortbydate">
  <li v-for="(item, index) in items" style="list-style:none">
    {{ index }} - {{ item.date }}
  </li>
</ul>
Comment

PREVIOUS NEXT
Code Example
Javascript :: image image using next and previous button in javascript 
Javascript :: apex express 18 forgot password 
Javascript :: console log update status bar 
Javascript :: using chalk and morgan together 
Javascript :: 4. You want to print the incremental count each time you instantiate a object using new in JS 
Javascript :: use vue cdn with firestore 
Javascript :: react hooks simple projects 
Javascript :: asjasfawepiowjpowlklkcdlkdLkdlkskskjskknisbsbu 
Javascript :: create javascript array from datalist dynamically 
Javascript :: node js reuire json shows onject 
Javascript :: nodejs multipart/x-mixed-replace; boundary=BoundaryString 
Javascript :: javascript file access to resources asp.net mvc 
Javascript :: js extract all tags not have attr 
Javascript :: rangeSlider format price js 
Javascript :: what is event in function inside prantesisi 
Javascript :: js fill array with count elements 
Javascript :: decrease touchableopacity in react native 
Javascript :: javascript and python graphs for data analysis 
Javascript :: gravity forms vote up or down 
Javascript :: bundle all css js files 
Javascript :: run nodes cleos 
Javascript :: JavaScript Implementation of Linear Search 
Javascript :: javascripte 
Javascript :: array.of 
Javascript :: How to get a factorial number 
Javascript :: change nav color on scroll vanilla js 
Javascript :: is the g required at the end of a regex expression 
Javascript :: hidden vue js 
Javascript :: react userefrence example 
Javascript :: instafeeed.js pulls back unknown for image file 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =