Skip to content
Advertisement

How can I group sections within a table?

I am using Vue with Element UI to create a table. Currently I am trying to figure out a possible way to add a year/name to the popup and hit save to have it show up as one of those headers shown in the ss with ‘add trim’ next to it? Add trim button would add those rows to the table but only for that model year/name group.

To sum things up, I’m looking for a way to associate certain rows to the headers that say the models name/year.enter image description here

JavaScript

Advertisement

Answer

You may want to add multiple tbody elements to your table, one for each model of vehicle. This lets you group the rows so your “Add Trim” script can target whichever group it’s part of.

This example is sloppy and uses .insertAdjacentHTML and some formatting hacks. In real life, I’d use a series of .createElement and .appendChild calls (or even better, <template> elements whose contents could be reused for each button click) — but hopefully this at least makes the idea clear.

(I pre-populated the input fields to make the demo easier to use.)

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement