0

How to show only 1st row from a Bootstrap table and via checkbox to show the rest of the rows? The bootstrap table and checkbox are in different components.

<b-table hover small responsive bordered stacked
         :fields="fields"
         :items="items">
</b-table>

Here is table's HTML structure: enter image description here

Here is how I would like to be:

1sta stage: enter image description here

2nd stage, after click event:

enter image description here

1
  • you'd use different items depending on the state of the checkbox, I guess Commented Jun 27, 2023 at 6:31

2 Answers 2

2

Your code will look like this:

<template>
  <div>
    <b-table
      hover
      small
      responsive
      bordered
      stacked
      :fields="fields"
      :items="showAllRows ? items : [items[0]]"
    >
    </b-table>

    <b-form-checkbox v-model="showAllRows">Show all rows</b-form-checkbox>
  </div>
</template>

<script>
import { BTable, BFormCheckbox } from "bootstrap-vue";
export default {
  components: [BTable, BFormCheckbox],
  data: () => ({
    fields: ["name", "money"],
    items: [
      { name: "test1", money: 2 },
      { name: "test2", money: 2 },
    ],
    showAllRows: false,
  }),
};
</script>

I tested for you and is working.

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

Comments

0

<template>
  <table>
    <thead>
      <tr>
        <th>Example 1</th>
        <th>Example 2</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="(item, index) in limitedItems" :key="index">
        <td>{{ item.Example1}}</td>
      </tr>
    </tbody>
  </table>
</template>


<script>
export default {
  data() {
    return {
      items: [
        { column1: 'Value 1', column2: 'Value 2' },
      ],
      maxRows: 5 
    };
  },
  computed: {
    LimitItems() {
      return this.items.slice(0, this.maxRows);
    }
  }
};
</script>

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.