Issues Arising with Examples of Fixed Header Tables in Angular 7

I've encountered a major issue with fixed header tables in relation to my Angular application. Utilizing the examples provided here and here, I initially thought it was a problem within my component. However, after embedding the same code into my index.html page without implementing the Angular app, the issue persisted. It's worth mentioning that I am still using ng serve to run the application locally. My CSS includes:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.0/css/bootstrap.min.css" />
<style type="text/css">
  .table-fixed tbody {
    height: 200px; overflow-y: auto; width: 100%;
  }
  .table-fixed thead, .table-fixed tbody, .table-fixed tr, .table-fixed td, .table-fixed th {
    display: block;
  }
  .table-fixed tr:after {
    content: ""; display: block; visibility: hidden; clear: both;
  }
  .table-fixed tbody td,
  .table-fixed thead > tr > th {
    float: left;
  }
  .table > thead > tr > th,
  .table > thead > tr > td {
    font-size: .9em;
    font-weight: 400;
    border-bottom: 0;
    letter-spacing: 1px;
    vertical-align: top;
    padding: 8px;
    background: #51596a;
    text-transform: uppercase;
    color: #ffffff;
  }
</style>

Following the CSS, in my HTML file, I have the table set up as follows:

    <table class="table table-fixed">
      <thead>
        <tr>
          <th class="col-xs-2">#</th><th class="col-xs-8">Name</th><th class="col-xs-2">Points</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td class="col-xs-2">1</td><td class="col-xs-8">Mike Adams</td><td class="col-xs-2">23</td>
        </tr>
        <tr>
          <td class="col-xs-2">2</td><td class="col-xs-8">Holly Galivan</td><td class="col-xs-2">44</td>
        </tr>
        ...
      </tbody>
    </table>

However, upon rendering the page, I am faced with the following output:

https://i.sstatic.net/GJflm.png

I'm seeking assistance to comprehend why this setup functions well in other examples but fails when integrated into my angular application locally.

UPDATE:

The discrepancy might arise from using Bootstrap 4 instead of Bootstrap 3. As per jahller's insight, switching back to Bootstrap 3.3.7 resolved the issue. Nevertheless, since my project is built with Bootstrap 4, could someone direct me towards an example that aligns with Bootstrap 4?

UPDATE 2:

In accordance with jahller's advice, the problem stemmed from utilizing col-xs-{num} classes for the table columns. Swapping them out with col-{num} classes successfully enabled the scrollable table with fixed headers functionality!

Answer №1

It appears that the example you referenced is using Bootstrap 3 instead of Bootstrap 4. To see the correct version in action, please check out the app.component.html file in this StackBlitz demo: https://stackblitz.com/edit/angular-v8mxae

In the demo, I have imported the Bootstrap version matching the one used in your CodePen example:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />

This should resolve any compatibility issues you were experiencing.

*Edit

If you wish to use Bootstrap 4 instead, simply remove the xs part from the col- classes as the grid system has changed slightly from Bootstrap 3 to 4. For example, replace col-xs-2 with col-2, and so on for other classes.

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

handling a click event for an unresponsive ID (or so I assume)

After developing a pop-up button module using Bootstrap for integration into all product pages, I encountered a challenge that I need help with. The problem is outlined below. This is my first time posting here, so I'm open to feedback on the necessi ...

Do floating divs still wrap even when the container has a no-wrap property?

I've been searching for answers to my questions for hours now, but haven't found a satisfactory solution yet. Can anyone help me out? Here is the link to my jsfiddle: http://jsfiddle.net/foreyez/Mr2ER/ This is the simple markup I am working wit ...

Ways to customize the background color of child cells in a table

I've implemented material-table in this UI and I'm currently working on customizing the style of specific cells only when the onTreeExpandChange is true. Essentially, my goal is to change the background color for cells 2 & 3. Check out the s ...

Troubles with CSS grid design

Could someone assist me with my grid layout for a project on free code camp? I am trying to display 3 of my portfolio pages in a row using a grid layout, but I'm having trouble getting the middle page to align properly with the others. Since I am new ...

Achieving the perfect alignment for a slideshow in CSS and HTML

Greetings everyone! I am looking to center my slideshow on my website and would greatly appreciate any assistance. ISSUE I am trying to center the logo and the entire slideshow, but as you can see, it is slightly off-center to the right. VIEW ISSUE(IMG) ...

Having trouble importing CSS in ReactJS?

While working on my project based on next.js, I encountered a situation where loading CSS in other pages was successful: import css from './cssname.css'; <div className={css.myclass}></div> However, now that I am implementing a ligh ...

Following the npm package upgrade for the Angular application, the functionality of the sass-loader has ceased to operate

After updating to Angular 13 from Angular 12 and making some changes to other NPM packages, I encountered an unexpected error when trying to serve my application. The error message is quite complex and difficult to comprehend: ./src/styles/ag-grid.scss.web ...

Expanding the content width of Bootstrap Nav Pills

I'm currently working with Bootstrap pills that feature two tabs. I would like to customize the width of the tab content container differently for each tab, but I'm unsure how to achieve this. The tab-content class currently sets the same width f ...

Troubleshooting issues with jQuery background-position animation and CSS sprites functionality

Trying to add animation to my navigation links background using a Css sprite. Check out the picture here: $(document).ready(function(){ $('nav a') // Move the background on hover .mouseover(function(){ $(this).stop().animate({ba ...

Preserving form input after an unsuccessful submission: A simple guide

As a beginner in the coding world, I am currently working on creating a contact form using PHP. One of the features I've included is a reCaptcha that must be checked before submitting the form. However, if the user forgets to check the reCaptcha and h ...

Unable to execute two queries in the MariaDB SQL server due to a syntax error when utilizing Angular in conjunction with Sequelize

I encountered an issue while attempting to delete records from two separate tables in my database using a SQL command. The goal was to merge two queries for deletion. defaultAdapter.query('DELETE FROM reasons WHERE name = :name') defaultAdapter. ...

An ample gap exists amongst the playing cards

Hey everyone, I know there will be a question about this but I can't seem to find it. I really need some space between the cards in the grid view. Also, having the "Read more" link towards the bottom right would be great. Thanks for any assistance! &l ...

Retrieve characters preceding and following a space (JavaScript)

In my Angular component, I have a phone number field. For example, +36 42534534534 I am trying to extract the code before the space and the phone number after the space. This is how I am currently handling it: set phoneNumberResult(value: string) { ...

Can anyone suggest a more efficient method for implementing jQuery toggle?

Summary: I have a customized javascript calendar that offers different viewing options such as day, week, and month. These views display events with specific class names. My current challenge is finding an effective method to toggle the visibility of thes ...

Exploring the Nested Components Feature in Ionic 4

I am currently in the process of transitioning my application from Ionic 3 to Ionic 4, and I have noticed that async and await calls are now being used for each component. While I understand the reasoning behind this change, in my Ionic 3 app, I had a nest ...

Overflow scroll block containing a table within a div element

I am working on displaying a loop of records fetched from the database. I want to place these records inside a div block with overflow so that users can scroll through a long list easily. However, when I try to implement the below code, the appearance of t ...

Only 1 argument was provided instead of the expected 2 when attempting to update Firebase through Ionic

I encountered an issue while trying to update Firebase from Ionic. Below is the function I used to update the data. Below is the TypeScript code: updateLaporan() { this.id = this.fire.auth.currentUser.uid; this.db.list('/laporan/'+thi ...

Is Angular 4 having trouble with certain video file extensions for video previews?

I'm currently facing an issue with video previews. I am able to display mp4 file extensions for the preview, but other file extensions like mpeg, m4v, wmv, etc. are not working with the current code. Even though I added all file types in the video sr ...

CSS media queries fail to accurately detect the screen size of the device

I am currently developing a mobile web application and have implemented a media query to specifically target phones with a screen height lower than that of the iPhone X+ (812px): @media (max-height: 811px) { } While this media query works flawlessly on ...

Guide to creating a search-enabled dropdown menu

Recently, I created a dropdown menu using Bootstrap. The code I used can be found here: http://getbootstrap.com/docs/4.0/components/dropdowns/ <div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownM ...