Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jcc5018's avatar

How do i add tabs to a long table (lots of columns)

I have a few tables with a lot of data that I would like to display. Instead of scrolling, i would like the option to group datasets into tabs.

so if tab one has columns id, model_name, [columns A-F]

tab 2 may have id, model_name, [columns G-M] and so forth.

in my particular model, i have about 5 such groupings each with about 6 columns.

The tabs function in the docs only seem to serve to filter the displayed data instead of grouping a bunch of columns into a more manageable display

Is there functionality for this request?

0 likes
6 replies
LaryAI's avatar
Level 58

To achieve the functionality of grouping columns into tabs, you can use a combination of JavaScript (or a JavaScript framework like Vue.js or React) and CSS to create a tabbed interface where each tab displays a different set of columns from your table. Below is a simple example using plain HTML, CSS, and JavaScript to illustrate the concept.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tabbed Tables</title>
<style>
  .tab-content {
    display: none;
  }
  .tab-content.active {
    display: table;
  }
  .tab-buttons {
    margin-bottom: 10px;
  }
  .tab-buttons button {
    padding: 5px 10px;
    cursor: pointer;
  }
</style>
</head>
<body>

<div class="tab-buttons">
  <button onclick="openTab(event, 'tab1')">Tab 1</button>
  <button onclick="openTab(event, 'tab2')">Tab 2</button>
  <!-- Add more buttons for additional tabs -->
</div>

<div id="tab1" class="tab-content active">
  <table>
    <!-- Table with columns A-F -->
    <tr>
      <th>ID</th>
      <th>Model Name</th>
      <!-- Add headers for columns A-F -->
    </tr>
    <!-- Add rows for data -->
  </table>
</div>

<div id="tab2" class="tab-content">
  <table>
    <!-- Table with columns G-M -->
    <tr>
      <th>ID</th>
      <th>Model Name</th>
      <!-- Add headers for columns G-M -->
    </tr>
    <!-- Add rows for data -->
  </table>
</div>

<!-- Add more divs for additional tabs -->

<script>
function openTab(evt, tabName) {
  var i, tabcontent, tablinks;
  tabcontent = document.getElementsByClassName("tab-content");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }
  tablinks = document.getElementsByClassName("tab-buttons")[0].getElementsByTagName("button");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }
  document.getElementById(tabName).style.display = "table";
  evt.currentTarget.className += " active";
}
</script>

</body>
</html>

In this example, we have two buttons that correspond to two different tabs. Each tab has a div with a class of tab-content. Initially, all tab-content divs are hidden except for the first one, which has an additional class active to make it visible.

The openTab function is called when a tab button is clicked. It hides all tab contents and then shows the one corresponding to the clicked tab. It also updates the active class on the buttons to reflect the current selection.

You can add more tabs by creating additional buttons and corresponding tab-content divs. Make sure to update the openTab function if you add more complex logic or additional features.

This is a basic example, and you might need to adjust it to fit the framework or library you're using in your project. If you're using a JavaScript framework like Vue.js or React, you would handle the tab switching logic within your components and use the framework's reactivity system to show and hide the appropriate table columns.

Tray2's avatar

Rather than display everything, I would display the most important things, and then either show everything in a show view, or load the information in a modal, or below the records when clicked.

1 like
jcc5018's avatar

@Tray2 I'm sorry, but my question is how do I display data in tabs? It wasn't asking for what you would do instead of tabs. I have a reason for wanting data displayed a certain way. I don't need to start a debate as to why, I only want to address the question asked.

Every project has different needs. Please don't assume everything aligns with how you may have done a different project.

Thanks

martinbean's avatar

@jcc5018 This is like, the third question I’ve seen from you recently where you’ve just been shirty and bordering on rude.

People like myself and @tray2 are here to help you. We’re problem solvers. When we see people describe a problem that may have another solution to the one you’re asking about then it’s only natural to say, “Have you considered doing X instead of Y?” If you have, all you need to do is say so, and maybe a brief explanation as to why it didn’t work out or isn’t suitable. Then every one can move on. Otherwise, if you just want the exact questions you ask answered with absolutely no deviation, then you may as well just go ask ChatGPT.

1 like
jcc5018's avatar

@martinbean I'm sorry that I get a bit frustrated when I ask a question and people choose to totally ignore it. This happens often, and it is aggravating cause i really dont like feeling like i have to defend how I choose to structure something. So sorry for the attitude. but im really just trying to maintain focus to the specific question asked.

If they would like more details to better understand the scope I am working with fine then they can ask, but there is also a bit of, I don't want to share everything as I don't want to give away what I'm building.

Is it not reasonable to think that sometimes the people asking the questions actually know what they want and need a solution to build exactly that? They don't need alternative suggestions from people who don't even know what I am attempting to accomplish.

If I go to a car dealer and tell them I want a cd player installed to play the hundreds of cds I own, and they insist on installing a mp3 player or something else cause thats the latest tech, wouldn't you also get a bit mad? The need is to play cds, not just listen to music.

I specifically want tabs so I can at a glance compare a specified set of data for a given model.

One tab will have the basic model info, next tab will display demographic data for those same rows of data. Another might display how much I am making with different related models and so forth.

I don't want to click to see those results for 1000+ records. I want to sort, filter, and review those results at a glance

So again... how can I make a set of tabs that simple show or hide a group of columns?

Something like

Tab::make('group1') ->columns([

Insert columns])

Tab::make ('group2')

->columns([ Insert differnt columns])

And so forth

As far as I know this functionality does not yet exists in filament, but I might have missed something, thus the question.

jlrdw's avatar

+1 to @tray2 answer. Only select main pertinent columns at first and use ORDER BY as necessary.

1 like

Please or to participate in this conversation.