1

How do we add a horizontal scroll bar to a mat table with angular table sticky header ?

enter image description here

#css code

#table {
  width: 100%;
}
#table tr.mat-row{
  height: 40px;
}

#html code

1

1 Answer 1

2

Please take a look at this post : Mat Table with sticky header and Horizontal ,vertical scroll bar

You can set the width and height to the div container wrap around the mat-table. On stylesheet, you can apply something like this:

.example-container {
  width: 100%;
  height: calc(100vh - 32px);
  overflow: auto;
}

Example with horizontal and vertical scroll: https://stackblitz.com/edit/angular-hdg9xh-uxkaeh

To remove vertical scroll adjust the .example-container css class to be

.example-container {
  width: 100%;
  height: calc(100vh - 32px);
  overflow-x: auto;
  overflow-y: hidden !important;
}

Example : https://stackblitz.com/edit/angular-hdg9xh-3xyt8z?file=src%2Fapp%2Ftable-sticky-columns-example.css

If you want to scroll through data just horizontally you would want the first column to act as the table header.

Example enter image description here

<table>
  <tr>
    <th>Date</th>
    <td>12 February</td>
    <td>24 March</td>
    <td>14 April</td>
  </tr>
  <tr>
    <th>Event</th>
    <td>Waltz with Strauss</td>
    <td>The Obelisks</td>
    <td>The What</td>
  </tr>
  <tr>
    <th>Venue</th>
    <td>Main Hall</td>
    <td>West Wing</td>
    <td>Main Hall</td>
  </tr>
</table>
Sign up to request clarification or add additional context in comments.

21 Comments

How do we remove the vertical scroll ? I only need the horizontal scroll.
I added to my answer on how you can just do the horizontal scroll. Your x axis is your horizontal and your y axis is vertical.
my goal Sir is to add a horizontal scroll if there are already multiple columns without the vertical inner scroll and the table header columns should be sticky without the vertical inner scroll and just by using the window scroll.
the problem with your ssecond example Sir @Steve is that the sticky is not working without the inner vertical scroll , it should work using the window scroll
how does the sticky work using the window Scroll ? ..that is my goal Sir
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.