最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - HideShow Multiple Column in V-Data-Table - Stack Overflow

programmeradmin1浏览0评论

May I ask for your help, I'm currently working making the columns show/hide using vuetifyjs, I stumbled on these reference:

putedHeaders () {
  if(this.hideCalories){
    return this.headers.filter(header => header.text !== "Calories")
  }

  return this.headers;
}

},

My problem on it is that it can only hide 1 header/column. Can you help me to make it hide multiple headers. I want to achieve these kind of output:

Thank you very much.

May I ask for your help, I'm currently working making the columns show/hide using vuetifyjs, I stumbled on these reference:

https://codepen.io/anon/pen/jeWRvN

putedHeaders () {
  if(this.hideCalories){
    return this.headers.filter(header => header.text !== "Calories")
  }

  return this.headers;
}

},

My problem on it is that it can only hide 1 header/column. Can you help me to make it hide multiple headers. I want to achieve these kind of output:

Thank you very much.

Share Improve this question edited Sep 4, 2019 at 14:32 Ace Valdez asked Sep 4, 2019 at 14:07 Ace ValdezAce Valdez 2614 silver badges8 bronze badges 6
  • 1 do you want to hide fat and carbs headers also and their columns ? – Boussadjra Brahim Commented Sep 4, 2019 at 14:14
  • What are all the columns need to hide? you just want to remove the specific columns or remove all, on click on the Hide Calories? – Sam Commented Sep 4, 2019 at 14:16
  • @BoussadjraBrahim my apologies if it was not that clear, I've edited my question/post with an image. Hopefully that would make it more clearer. thank you guys – Ace Valdez Commented Sep 4, 2019 at 14:33
  • @Sam my apologies if it was not that clear, I've edited my question/post with an image. Hopefully that would make it more clearer. thank you guys – Ace Valdez Commented Sep 4, 2019 at 14:34
  • the screenshot doesn't correspond to the codepen snippet – Boussadjra Brahim Commented Sep 4, 2019 at 14:36
 |  Show 1 more ment

1 Answer 1

Reset to default 5

The headers property can be puted

  puted: {
    headers() {
      let headers = [
        {
          text: 'Dessert (100g serving)',
          align: 'left',
          sortable: false,
          value: 'name'
        }
      ]

      if (!this.hideCalories) {
        headers.push({ text: 'Calories', value: 'calories' })
      }
      if (!this.hideFat) {
        headers.push({ text: 'Fat (g)', value: 'fat' })
      }
      // ...

      headers.push({ text: 'Carbs (g)', value: 'carbs' })
      headers.push({ text: 'Protein (g)', value: 'protein' })
      headers.push({ text: 'Actions', value: 'name', sortable: false })

      return headers
    }
  }

Then pass headers to table as before.

发布评论

评论列表(0)

  1. 暂无评论