简体   繁体   中英

Expand/Collapse All Actions in a bootstrap Vue.js table

I made a Vue.js bootstrap table for loading some data from local JSON files. I've implemented an option for Show/Hide details of specific row (shows full data message of a specific row). I'm trying to implement a checkbox or a button where I can expand/collapse (Show/Hide) details of all rows. I've tried some things, but it just doesn't seem to work. I don't have many experiences with Vue. https://imgur.com/BaTfgci --> this is how the app looks right now https://codepen.io/frane_caleta/pen/KKPMKrL --> codepen of my code, you won't be able to load it without JSON file though https://imgur.com/a/23jx0lZ --> JSON data example

Feel free to ask if you need any more details about this app / project!

Part of my code where I'm showing/hiding details of specific row:

 <b-table 
    id="myTable" 
    class="text-center" 
    :small="small" 
    :bordered="bordered" hover head-variant="dark" 
    v-if="activeFields.length > 0" 
    stacked="md"
    :items="cptItems" :fields="activeFields" :current-page="currentPage" :per-page="perPage"
    :filter="filter" :sort-by.sync="sortBy" :sort-desc.sync="sortDesc" @filtered="onFiltered"
    :tbody-tr-class="rowClass"
    >    
    <template slot="actions" slot-scope="row">
        <b-button size="sm" @click="row.toggleDetails">
            {{ row.detailsShowing ? 'Hide' : 'Show' }} Details
        </b-button>
    </template>
    <template slot="row-details" slot-scope="row">
        <b-card>
            <b-card-text id="msg" class="text-break text-left" v-html="row.item.message"></b-card-text>
        </b-card>
    </template>
</b-table>

You can simply create a method which runs over each item in the table collection and set _showDetails to either true for open and false for closed.

In the codepen i also created a computed property which checks if any of the elements in the collection is open and returns true if so. That way i can create a single button to toggle all rows.

https://codepen.io/Hiws/pen/dEqvEL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM