sap.m.Table - Vertical Scrolling with Fixed Header

Mahendra Kulkarni picture Mahendra Kulkarni · Jun 14, 2016 · Viewed 21k times · Source

I have one table having lots of data. Now I want to scroll vertically with table header fixed. can I achieve this?

Here is my code:

 onInit: function() {
   var data = new JSONModel("Model/data.json");
   this.getView().setModel(data);
   var otable = this.getView().byId("PlaceIt");
   otable.bindItems("/employees", new ColumnListItem({
     cells: [
       new Text({
         text: "{name}"
       }),
       new Text({
         text: "{Physics}"
       }),
       new Text({
         text: "{Chemistry}"
       }),
       new Text({
         text: "{Maths}"
       }),
       new Text({
         text: "{English}"
       })
     ]
   }));
   otable.setModel(data);
   var oScrollContainer = new ScrollContainer({
     height: "100px",
     vertical: true,
     focusable: true,
     content: [oTableItems]
   });
 },
<Table id="PlaceIt">
  <columns>
    <Column>
      <Text text="Student Name" />
    </Column>
    <Column>
      <Text text="Physics" />
    </Column>
    <Column>
      <Text text="Chemistry" />
    </Column>
    <Column>
      <Text text="Maths" />
    </Column>
    <Column>
      <Text text="English" />
    </Column>
  </columns>
  <!-- ... -->
</Table>

I tried using sap.m.ScrollContainer control but I'm not getting anything.

Here is a demo.

Answer

Boghyon Hoffmann picture Boghyon Hoffmann · Feb 16, 2018

As of v1.54, the property sticky is publicly available.

sticky
Defines the section of the sap.m.Table control that remains fixed at the top of the page during vertical scrolling as long as the table is in the viewport.

Once its value is set to "ColumnHeaders", the headers will stay fixed while scrolling.

sapui5 openui5 ui5 sap.m.Table sticky fixed column headers

Be aware that this feature is supported only by modern browsers.