sap.m.Table - Vertical Scrolling with Fixed Header

假装没事ソ 提交于 2019-12-29 05:35:08

问题


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.


回答1:


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.

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


  • Demo: https://jsbin.com/ticivew/edit?js,output
  • Property description
  • Other sticky optionsv1.56 - The syntax for assigning multiple values in XMLView looks as follows:

    <Table sticky="HeaderToolbar,InfoToolbar,ColumnHeaders">
    



回答2:


Not sure why you don't want to use sap.m.Table, but here's an example nonetheless:

sap.ui.controller("view1.initial", {
    onInit : function(oEvent) {
        var oModel = new sap.ui.model.json.JSONModel();
        oModel.setData({
            data : [
                {
                    "col1": "at curabitur vestibulum",
                    "col2": "porttitor pharetra rutrum",
                    "col3": 93
                },
                {
                    "col1": "hendrerit dui fringilla",
                    "col2": "adipiscing suspendisse lorem",
                    "col3": 36
                },
                {
                    "col1": "placerat vel placerat",
                    "col2": "suspendisse quis sit",
                    "col3": 9
                },
                {
                    "col1": "sagittis at sed",
                    "col2": "malesuada aliquam sit",
                    "col3": 26
                },
                {
                    "col1": "donec donec sed",
                    "col2": "dui tempor nunc",
                    "col3": 38
                },
                {
                    "col1": "sed vitae fringilla",
                    "col2": "vestibulum pretium dolor",
                    "col3": 17
                },
                {
                    "col1": "scelerisque curabitur orci",
                    "col2": "sit sollicitudin amet",
                    "col3": 16
                },
                {
                    "col1": "libero lacus pulvinar",
                    "col2": "lorem velit elit",
                    "col3": 15
                },
                {
                    "col1": "convallis in at",
                    "col2": "fringilla sagittis magna",
                    "col3": 35
                },
                {
                    "col1": "dolor magna sed",
                    "col2": "at turpis tortor",
                    "col3": 3
                },
                {
                    "col1": "elit mi tortor",
                    "col2": "quis aenean turpis",
                    "col3": 32
                },
                {
                    "col1": "ipsum et magna",
                    "col2": "amet massa aliquam",
                    "col3": 59
                },
                {
                    "col1": "eget magna at",
                    "col2": "pharetra amet porta",
                    "col3": 69
                },
                {
                    "col1": "magna et scelerisque",
                    "col2": "aliquam vitae nullam",
                    "col3": 4
                },
                {
                    "col1": "velit etiam odio",
                    "col2": "lorem lacus magna",
                    "col3": 28
                },
                {
                    "col1": "at scelerisque lorem",
                    "col2": "facilisis odio dolor",
                    "col3": 4
                },
                {
                    "col1": "amet ipsum massa",
                    "col2": "sollicitudin sed tortor",
                    "col3": 54
                },
                {
                    "col1": "velit tincidunt massa",
                    "col2": "risus tortor massa",
                    "col3": 7
                },
                {
                    "col1": "id amet adipiscing",
                    "col2": "aliquam vitae adipiscing",
                    "col3": 94
                },
                {
                    "col1": "lorem massa lacus",
                    "col2": "malesuada ac sed",
                    "col3": 27
                }
            ]
        });

        this.getView().setModel(oModel);
    }
});


sap.ui.xmlview("main", {
    viewContent: jQuery("#view1").html()
})
.placeAt("uiArea");
/* extra CSS classes here */
<script id="sap-ui-bootstrap"
    src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
    data-sap-ui-theme="sap_bluecrystal"
    data-sap-ui-xx-bindingSyntax="complex"
    data-sap-ui-libs="sap.ui.commons"></script>

<div id="uiArea"></div>

<script id="view1" type="ui5/xmlview">
    <mvc:View 
      controllerName="view1.initial"
      xmlns="sap.ui.commons"
      xmlns:l="sap.ui.commons.layout"
      xmlns:t="sap.ui.table"
      xmlns:core="sap.ui.core"
      xmlns:mvc="sap.ui.core.mvc" >
        <t:Table rows="{/data}" visibleRowCount="5">
            <t:columns>
                <t:Column width="100px">
                    <t:label><Label text="col1" /></t:label>
                    <t:template><TextView text="{col1}" /></t:template>
                </t:Column>
                <t:Column width="100px">
                    <t:label><Label text="col2" /></t:label>
                    <t:template><TextView text="{col2}" /></t:template>
                </t:Column>
            </t:columns>
        </t:Table>
    </mvc:View>
</script>



回答3:


You will need two tables. First table will have only columns and second will contain items to be displayed with empty column headers.

Second table will be the content of ScrollContainer.

demo



来源:https://stackoverflow.com/questions/37809148/sap-m-table-vertical-scrolling-with-fixed-header

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!