How can I pass data that is clicked on in a Bootstrap-vue b-table to a b-card that is not within the table or template?

I am currently working on a Bootstrap-Vue b-table that utilizes the @row-clicked event to showcase associated content in a card that expands below the selected row. While this feature works beautifully, the client has now requested that the displayed data appear beside the table, similar to a sidebar b-card.

In an attempt to achieve this layout, I have tried relocating the

<template #row-details="row">...</template>
from within the b-table to a standalone b-card like this:

  <b-table :items="dataDevices" @row-clicked="onRowClicked">
    <!-- the template typically resides here and functions correctly  -->
  </b-table> 
  <template #row-details="row">
    <b-card>{{ row.item.serno }}</b-card>
  </template>

Unfortunately, this approach does not seem to work as expected. I also attempted altering the template syntax to

<template slot="row-details" slot-scope="row">
but encountered no success.

Despite my extensive Google research skills, I have been unable to locate any instances of individuals implementing this technique.

While I acknowledge that @row-clicked provides access to row data and operates seamlessly with templates inside the b-table component, I believe there must be a way to transmit row data to elements outside the b-table structure.

For those who have explored presenting b-table row data in this manner, how did you approach it? Any guidance or references to relevant examples/documentation would be greatly appreciated.

Perhaps I need to develop an event handler function for @row-clicked that effectively transfers the data to a specific b-card identified by an ID. At this stage, I'm simply brainstorming potential solutions.

If anyone can offer insights or direct me towards useful resources, it would be immensely helpful.

Answer №1

When the @row-clicked event is triggered, it sends the item object of the row that was clicked.

This means you have the option to store this object in a local property within the data section. This property can then be accessed and utilized outside of the table, such as within a <b-card>.

new Vue({
  el: "#app",
  data() {
    return {
      fields: ["isActive", "first_name", "last_name", "age"],
      items: [{
          isActive: true,
          age: 40,
          first_name: 'Dickerson',
          last_name: 'Macdonald'
        },
        {
          isActive: false,
          age: 21,
          first_name: 'Larsen',
          last_name: 'Shaw'
        },
        {
          isActive: false,
          age: 89,
          first_name: 'Geneva',
          last_name: 'Wilson'
        }
      ],
      selectedItem: null
    }
  },
  methods: {
    onRowClicked(item) {
      this.selectedItem = item
    }
  }
})
<link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="24464b4b50575056455464100a110a17">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" />

<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a8deddcde89a869e86999a">[email protected]</a>/dist/vue.min.js"></script>
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="187a77776c6b6c6a7968356e6d7d582a362a29362a">[email protected]</a>/dist/bootstrap-vue.js"></script>

<div id="app" class="p-3">
  <b-row>
    <b-col>
      <b-table :items="items" :fields="fields" bordered @row-clicked="onRowClicked" class="mb-0"></b-table>
    </b-col>
    <b-col>
      <b-card class="h-100">
        <pre v-if="selectedItem">{{ selectedItem }}</pre>
        <h4 class="text-center" v-else>
          No item selected.
        </h4>
      </b-card>
    </b-col>
  </b-row>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

TypeScript in conjunction with Eslint is throwing an error stating it is unable to locate a particular

One of the modules is causing eslint complaints, even though it is installed and functioning properly in the code. Error message: Unable to resolve path to module '@azure/functions'.eslintimport/no-unresolved az/index.ts import { AzureFunction ...

Looking for a demonstration using dust.js or handlebars.js in a two-page format with express3.x and node?

Currently, I am in the process of selecting a templating engine to use. While I have come across numerous single-page examples utilizing template engines, I am specifically searching for a practical example that demonstrates handling two distinct pages whi ...

Ways to add margin-top to a card element without affecting the entire container-fluid

I'm attempting to change the background image of this container, but when I add margin-top to the card element, it shifts everything over the picture. Below is my Bootstrap4 code: #card.container-fluid { background-image: url("../images/picture2. ...

I'm having trouble using the splice() function to insert a substring into an array. What could be

Forgive me for the trivial question, but this is really bothering me. I'm trying to replicate the example on Mozilla's site: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice Could someone clarify why t ...

Implementing JavaScript logic to proceed to the following array within a 3D array once a specific condition is met

I'm currently tackling a challenge that requires me to obtain a specific number using a given 3D array. This array consists of 2D arrays, each containing the same number repeated x times. The parent array is sorted from largest to smallest. Here&apos ...

Smooth scrolling feature for Wordpress websites

I am currently in the process of converting an HTML5 template into a Wordpress theme. One specific feature I'd like to add is a custom scroll for Wordpress using the code: <script src="jquery.nicescroll.js"></script> DEPENDENCIES This cod ...

Unable to utilize jQuery library in AngularJS partial HTML files, despite being loaded in the index.html file

I have been working with a web template that utilizes jQuery image gallery and other elements. Now, I am looking to convert this template into an AngularJS structure. To do so, I have created partial HTML pages like slider.html or contact.html along with t ...

Navigating the integration of internal Bootsrap 5.2 with Laravel 7

Hi there, I am new to the Laravel framework and I am attempting to link my Bootstrap v5.2 with my Laravel v7 project. However, I seem to be having trouble connecting the two. I have stored the CSS and JS folders within a "bootstrap" folder at the same leve ...

What is the best way to format a string into a specific pattern within an Angular application

In my Angular component, I have 4 fields: customerName, startDate, and startTime. Additionally, I have a fourth field that is a textarea where the user can see the message that will be sent via email or SMS. Within my component, I have defined a string as ...

Populating inputs dynamically in React.js to receive values

Having recently transitioned to React from React Native, I am faced with a new challenge. I have an array of objects, let's say it contains 5 items. I used the map function to populate views based on the amount of objects, resulting in 5 headings and ...

Ways to display a confirmation message prior to deleting?

When deleting, I would like a confirmation message to appear upon clicking the delete button or image. If the user chooses 'Ok', then the deletion will proceed; however, if 'Cancel' is selected, nothing will happen. I attempted to disp ...

Is it possible to create a pitch shifter with the web-audio-api?

Creating a Pitch Shifter with Node.js Hello, I am new to web development! I am currently working on developing an online audio player that requires a pitch shifter. I have been attempting to grasp the concept of the web audio API, but find it challengin ...

Using PHP code to pass a value to JavaScript

I have both PHP and JavaScript code on my page, and I need to retrieve a value from PHP into my JavaScript code. Below is my JavaScript code: <script type="application/ld+json"> { "@context": "http://schema.org", "@type": "Bread ...

Saving the accurate x and y coordinates into the database

My website features draggable images that each have their own x and y positions. I am attempting to pass these values into a MySQL database, but I'm facing an issue where all the images are getting assigned the same x and y values in the database. In ...

Using Javascript to trigger form submission using arrow keys

There are four forms displayed on a single page, and I want each form to be submitted based on the arrow key that is pressed. <form name='go_north' action='' method='post'> <input type='hidden' name=' ...

What is the use of the typeof operator for arrays of objects in TypeScript?

How can I update the any with the shape of the options's object below? interface selectComponentProps { options: { label: string; value: string; }[]; } const SelectComponent: React.FC<selectComponentProps> = ({ options, }) => ...

Prevent methods from being called in a Typescript class after they have already

I encountered a scenario where I need to exclude certain methods from the return type of a class method once they have been called. Consider a class named Setup with methods step1, step2, and step3. class Setup { step1() { return this; } ...

The lack of intellisense in VS Code for Node.js poses a significant challenge for developers

I am facing a problem with IntelliSense in Visual Studio Code. Despite installing multiple extensions, it is not working as expected. The IntelliSense feature only shows functions and variables that have already been used in my code file. Below is the li ...

Access a file from the local system using JavaScript within a Django application

I am encountering an issue with fetching a .txt file in a folder using the fetch() function in JavaScript within a Django project. Whenever I try to call the file with fetch, a Django error occurs. (index):456 GET 404 (Not Found) The file I am trying to ...

JavaScript will continue to run uninterrupted even after refreshing the webpage

Has anyone else encountered the issue of a javascript on a page continuing to run even after the page is refreshed? From what I understand, javascript is single-threaded and should stop running when the page is refreshed. Just to provide some background, ...