Discover the easy way to provide a hyperlink for every row within a Bootstrap-vue table

I am working on a project that includes a table from bootstrap-vue. I am trying to add a link to each row, similar to the code snippet below:

<template #row>
 <div @click="goToPage">
    {{ item.name}}
 </div>
</template>

However, I am unsure of how to access the table tr element in Bootstrap. You can find my project on codesandbox. Any assistance on this matter would be greatly appreciated.

Answer №1

To enhance the functionality of your table, include the selectable attribute and listen for the row-selected event:

<b-table select-mode="single" ref="selectableTable" selectable @row-selected="onRowSelected" small :fields="fields" :items="items" responsive="sm">

Next, define the following method:

methods: {
  onRowSelected(item) {
    console.log(item)
  }
}

Answer №2

If you want to handle row clicks, you can utilize the @row-clicked event. This event is triggered whenever a row is clicked on.

When this event is triggered, it passes the item associated with the clicked row, allowing you to access any necessary information from that item. Additionally, it provides the index of the row and the native click event.

new Vue({
  el:"#app",
  data: () => ({
    items: [
      { age: 40, first_name: 'Dickerson', last_name: 'Macdonald' },
      { age: 11, first_name: 'Larsen', last_name: 'Shaw' },
      { age: 89, first_name: 'Geneva', last_name: 'Wilson' },
      { age: 38, first_name: 'Jami', last_name: 'Carney' }
    ]
  }),
  methods: {
    onRowClicked(item, index, event) {
      console.log(item)
    }
  }
});
<link type="text/css" rel="stylesheet" href="//unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fa9895958e898e889b8abaced4cfd4c9">[email protected]</a>/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="//unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="debcb1b1aaadaaacbfaef3a8abbb9eecf0eceff0ec">[email protected]</a>/dist/bootstrap-vue.css" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.12/vue.min.js"></script>
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="274548485354535546570a51524267150915160915">[email protected]</a>/dist/bootstrap-vue.js"></script>


<div id="app" class="p-3">
  <b-table striped hover :items="items" @row-clicked="onRowClicked"></b-table>
</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

Validating inputs with pristine Vue.js

I am working on creating a vue.js based form validation system that validates input on-the-fly without the need for page refresh. Currently, I have implemented the following code for email field validation: <div class="container" id="forms" > <l ...

Elevate your Material UI Avatar with an added level of

Attempting to give a MUI Avatar component some elevation or shadow according to the documentation provided here. <Avatar alt="Cindy Baker" src="/static/images/avatar/3.jpg" /> Enclosing the Avatar within a paper or Card element increases the size o ...

Syntax for making an Ajax call

Encountering an issue with my simple ajax post - data is not being passed successfully to the file (ajaxpost.php). Even though it posts to the file, the POST data is unavailable. var myKeyVals = {caption: "test"}; $.ajax({ //Ex ...

Exploring the Use of data- Attributes in SVG Circle Elements

Looking for a way to dynamically update the color of a Circle element in your SVG when it is clicked? You can achieve this by using jQuery's .css() method in conjunction with the data-* attribute. CHECK OUT AN EXAMPLE: STYLING IN CSS svg { height ...

Managing the rendering of a functional component using React/Redux

I have encountered an issue with my app where it updates too frequently. Within my reducer, there is a specific action called checkTasks. This action essentially scans through the list of current tasks and moves any expired tasks from the main tasks array ...

Texture spanning two sides

Currently tackling the challenge of creating a diamond shape with a unique texture. After successfully creating the desired geometry, I'm encountering difficulty in applying a texture to the diamond. The texture seems to be splitting on the face with ...

What is the process for adding a new property to a prop in React?

In my react component, there is a prop called bookShelf, which is an array of objects containing properties like title, author, and pageCount. I want to add a new property called shelf to each object in the array. I attempted the following: this.props.bo ...

Creating Flexnav Menu Buttons that automatically adjust their width based on the content within them

Is it possible to use flexnav without fixed width buttons? I would like all navigation items to only use the necessary width to display their text and padding. Currently, I have to divide 100% by the number of navigation items we have. This value is set w ...

Tips for executing embedded scripts within templates

I am using a controller to display the Instagram embedded code <div class="instagram_here" [innerHtml]="instagram_embeded_code"></div> However, it is only showing a blank Instagram block. https://i.stack.imgur.com/gNPDL.png I suspect there m ...

Copy the click function to a contenteditable <div> with spellcheck feature

When using a contenteditable <div> in Chrome, the native spell check feature will only work if the user manually clicks into the <div>. But what if you want to add a contenteditable <div> dynamically? Is there a way to trigger the spell c ...

Inject variables into the URL

Having access to an API that provides a list of images, I am presented with 5 parameters as listed below: The first parameter is the keyword for the search (e.g. flowers) The second parameter is size which has a default value The third parameter is orien ...

What could be the reason for this simple sails socket not functioning properly?

Just curious why the simple web socket code below isn't functioning? io.socket.on('user', function(event){ console.log("RECEIVED EVENT:",event); }) I have included sails.io.js in my index file and the above code is located in a test.js ...

Error encountered with VueJS API when running in production mode after executing `npm run build`

Currently, I am working on developing 2 applications that communicate data through an API. Everything runs smoothly until I execute npm run build. Strangely, I encounter an error (Failed to load resource: the server responded with a status of 404 (Not Foun ...

How to boost the value of a property within a MongoDB document with Mongoose

Recently, I've been dealing with an array of objects named "items". This array includes different objects and I need to search for each object in MongoDB using the "baseId" found in the Base Document. Once I locate the matching object, I aim to update ...

Avoiding the stacking of event listeners in React onClick when removing and re-adding the same listener

Is it possible to remove and add the same event listener in an onClick React event? The goal is to have an event listener added to the parent element when the target element is clicked, and then removed on the next click to prevent stacking. One issue tha ...

Why isn't the field I added to my state functioning properly?

Can anyone explain why I am getting names without the added selected field??? I can fetch names from my API JSON (1) and I'm attempting to modify it by adding the selected field (2). export default function Display() { ... const init ...

Bypassing the use of a div purely for aesthetics in Bootstrap 4

<div class="container-fluid"> <div class="row"> <div id="div#1" class="item color col-md-6"> col-md-6 </div> <div id="div#2" class="item col-md-6"> <div class="color"> col-md-6 < ...

Where should the logic for the Redux app be implemented for optimal performance?

My react-redux app features an action-creator that filters a list of objects based on a specified title: export const filterItems = (title) => dispatch => { axios.get(`/api/items/?title=${title}`) .then(res => { dispatch({ ...

Server error occurs in NodeJS site when the MongoDB database is not empty

I am currently utilizing Node.js in conjunction with MongoDB and Mongoose to facilitate my database connectivity. An intriguing issue arises when the database lacks any values: the callback function successfully renders the subsequent page (albeit without ...

Guide for downloading files synchronously from a URL using node.js

My current task involves downloading multiple files from Flickr using Flickr APIs and http.get() calls in a loop. I have an array containing image URLs and I am utilizing a 'download' function to save the pictures. When dealing with a large numb ...