A
A
adizh2022-02-26 11:30:15
Working with date/time
adizh, 2022-02-26 11:30:15

How to show filtered data from the calendar correctly?

There is a budget app in which you need to filter purchases based on the choice of the month (dropdown), only the first purchase is filtered.
dropdown:

<div class="selectMonth">
      <p @click="areOptionVisible = !areOptionVisible" class="selected">
        {{ selectedMonth }}
      </p>
      <div
        class="options"
        v-show="areOptionVisible"
        v-for="option in options"
        :key="option.value"
        @click="selectMonth(option)"
      >
        <p :value="option.value">{{ option.name }}</p>
      </div>
    </div>

selectMonth:
selectMonth(option) {
      this.selectedMonth = option.name;
      this.areOptionVisible = false;
this.sortedPro=[...this.products]
return this.sortedPro=this.sortedPro.filter((item) => {
  return item.dateInput.split('-')[1].split('')[1] //2022-02-26 === +option.value //номер месяца


      })
    },

Data is rendered via:
filteredPro(){
      if(this.sortedPro.length){
        return this.sortedPro
      }
       else{
         return this.products
       }
    }

Data:
<div class="expenses" v-show="this.filteredPro.length">
      <table class="table table-bordered border-primary today_tables">
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">Name</th>
            <th scope="col">Price</th>
            <th scope="col">Date</th>
            <th scope="col"></th>
          </tr>
        </thead>
        <tbody v-for="(pro, index) in filteredPro" :key="todo.id">
          <tr>
            <th scope="row">{{ index + 1 }}</th>
            <td>{{ pro.name }}</td>
            <td>{{ pro.price }} сом</td>
            <td>{{ pro.dateInput | moment }}</td>
            <td>
              <button class="btn btn-success" @click="editTodo(index)">
                edit
              </button>
            </td>
          </tr>
        </tbody>
      </table>
    </div>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question