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.

Allow colspan=(all) items

See original GitHub issue

I know this one might be a bit controversial/difficult, but wanted to throw it out there and see what y’all thought. I have the need to “group” things in a single table (single table so I get selectable support) and the most natural way of displaying the groupings I can think of would be to use a row where colspan is all the columns.

An quick-and-dirty example might be (of course, with much more beautiful styling)

Weapon Person
Study
Rope Professor Plum
Gun Colonel Mustard
Kitchen
Knife Mrs. White

Where the items coming in look like:

[
   {room: "Study", weapon: "Rope", person: "Professor Plum"},
   {room: "Study", weapon: "Gun", person: "Colonel Mustard"},
   {room: "Kitchen", weapon: "Knife", person: "Mrs. White"},
]

(although I’m more than happy to transform my items if the implementation is easier with a different representation)

My particular use case would include:

  • the ability to use tbody-tr-class (or similar) to style said rows
  • not have those rows selected in range mode (“skips” over them)

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
tmorehousecommented, Mar 21, 2019

Not needed…

You could do the following:

const items = [
  { category: 'a', foo: 1, bar: 2 },
  { category: 'a', foo: 3, bar: 4 },
  { category: 'b', foo: 5, bar: 6 },
  { category: 'b', foo: 7, bar: 8 },
  { category: 'c', foo: 9, bar: 10 }
]

and then loop through your items like so:

items.forEach((item, index) => {
  if (items[index+1] !== undefined && item.category !== items[index+1].category) {
    item._showDetails = true
    item.nextCategory = items[index+1].category
  }
})

And then pass this modified items to b-table, and then use the following slots:

<template slot="top-row" slot-scope="{ columns }">
  <!-- slot top-row requires you to provide your own td element(s) -->
  <td :colspan="columns">{{ items[0].category }}</td>
</template>
<template slot="row-details" slot-scope="{ item }">
  <!-- details slot already has a single TD with correct colspan -->
  {{ item.nextCategory }}
</template>

Should get you close to what you want.

0reactions
thejcannoncommented, Mar 22, 2019

Fair enough, thanks again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Colspan all columns - html - Stack Overflow
The best thing to do is set the colspan to the correct number to begin with. If your table has 5 columns, set...
Read more >
Colspan All Columns In HTML - Weston Ganger
So I needed to make a column span all remaining columns in the row but I didn't know what number to set it...
Read more >
Table Rowspan And Colspan In HTML Explained (With ...
Allows a single table cell to span the height of more than one cell or row. Why use colspan= or rowspan= ? Sometimes...
Read more >
column-span - CSS: Cascading Style Sheets - MDN Web Docs
The column-span CSS property makes it possible for an element to span across all columns when its value is set to all.
Read more >
HTML | colspan Attribute - GeeksforGeeks
The colspan attribute in HTML specifies the number of columns a cell should span. It allows the single table cell to span 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