question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<b-table>: can you target the `tbody` element to apply an event handler?

See original GitHub issue

As it is, i can create a slot and slot-scope it to the row or cell and then add an event listener to an object inserted into that cell or row (most obviously is @click event on a button inside of a table cell) but how can i scope a slot to the <tbody> or target the <tbody> and add an event to it?

in my application i’d want to add an @scroll event to the <tbody>… adding @scroll the the <b-table> doesn’t work. trying to scope a slot to the <tbody> doesn’t work since 'body’ is not an accepted argument for <b-table> scoped-slot argument. (row, cell, data are however)

if this is not possible can i propose a change to scoped slots to allow for scoping to 'body' or 'tbody'?

kind of interesting i can add events to row or to cell but not to the table itself.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
tmorehousecommented, Oct 29, 2018

Not the element itself, but the scroll event triggered from the tbody.

Basically we could do this inside of the b-table component:

  <tbody @scroll="$emit('bodyscroll',$event)">

and you would do this when using it:

<b-table @bodyscroll="onBodyScroll" ... >
methods: {
  onBodyScroll(event) {
    // event.target === tbody element
    // do something on scroll
  }
}
0reactions
tmorehousecommented, Aug 12, 2019

BootstrapVue 2.0.0-rc.28 (released today) introduces a new component <b-table-simple> which gives you control over the rendering of the table. You will need to handle managing your items and fields manually… but it is an alternative option.

Read more comments on GitHub >

github_iconTop Results From Across the Web

<tbody>: The Table Body element - HTML - MDN Web Docs
The HTML element encapsulates a set of table rows ( elements), indicating that they comprise the body of the table ( ).
Read more >
How to addEventListener to table cells - Stack Overflow
3 Answers 3 · First, get all the cells by their 'tag' ("td") using 'querySelectorAll' and save it as a list · Add...
Read more >
Tables in HTML documents
The TBODY start tag is always required except when the table contains only one table body and no table head or foot sections....
Read more >
Event delegation - The Modern JavaScript Tutorial
It will use event.target to get the clicked element and highlight it. ... In the handler table.onclick we should take such event.target and ......
Read more >
Striped Table with Rollovers | Events in JavaScript - Peachpit
As its name suggests, the checkEventSource function will check which element was the source of the event when the mouse moves over the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found