1. 程式人生 > >UI5-文檔-4.35-Responsiveness

UI5-文檔-4.35-Responsiveness

data gin formatter tail through demo for width row

在這一步中,我們將改進應用程序的響應能力。SAPUI5應用程序可以在手機、平板電腦和桌面設備上運行,我們可以對應用程序進行配置,以便為每個場景充分利用屏幕空間。幸運的是,SAPUI5控件類似於sap.m.Table已經提供了許多我們可以使用的特性。

Preview

技術分享圖片

A responsive table is hiding some of the columns on small devices

Coding

You can view and download all files at Walkthrough - Step 35.

webapp/view/InvoiceList.view.xml

<mvc:View
                controllerName="sap.ui.demo.walkthrough.controller.InvoiceList"
               xmlns="sap.m"
               xmlns:mvc="sap.ui.core.mvc">
        <Table
               id="invoiceList"
               class="sapUiResponsiveMargin"
               width="auto"
items="{ path : ‘invoice>/Invoices‘, sorter : { path : ‘ShipperName‘, group : true } }"> <headerToolbar>
<Toolbar> <Title text="{i18n>invoiceListTitle}"/> <ToolbarSpacer/> <SearchField width="50%" search="onFilterInvoices"/> </Toolbar> </headerToolbar> <columns> <Column hAlign="End" minScreenWidth="Small" demandPopin="true" width="4em"> <Texttext="{i18n>columnQuantity}"/> </Column> <Column> <Texttext="{i18n>columnName}"/> </Column> <Column minScreenWidth="Small" demandPopin="true"> <Texttext="{i18n>columnStatus}"/> </Column> <Column minScreenWidth="Tablet" demandPopin="false"> <Texttext="{i18n>columnSupplier}"/> </Column> <Column hAlign="End"> <Texttext="{i18n>columnPrice}"/> </Column> </columns> <items> <ColumnListItem type="Navigation" press="onPress"> <cells> <ObjectNumbernumber="{invoice>Quantity}" emphasized="false"/> <ObjectIdentifiertitle="{invoice>ProductName}"/> <Texttext="{ path: ‘invoice>Status‘, formatter: ‘.formatter.statusText‘ }"/> <Texttext="{invoice>ShipperName}"/> <ObjectNumber number="{ parts: [{path: ‘invoice>ExtendedPrice‘}, {path: ‘view>/currency‘}], type: ‘sap.ui.model.type.Currency‘, formatOptions: { showMeasure: false } }" unit="{view>/currency}" state="{= ${invoice>ExtendedPrice} > 50 ? ‘Error‘ : ‘Success‘ }"/> </cells> </ColumnListItem> </items> </Table> </mvc:View>

由於表的每行有多個單元格,我們必須為表定義列,並根據數據命名這些列。加入5個sap.m.Column列控件的列聚合和配置各略有不同:我們只需將標記< list >替換為< table >,就可以用表替換列表。該表有一個內置的響應特性,使我們能夠使應用程序更加靈活。表和列表共享相同的屬性集,因此我們可以簡單地重用這些屬性和排序器。

? Quantity: 這一列將包含一個短數字,因此我們將對齊設置為End(在LTR語言中表示“正確”),並將寬度設置為4em,這對於列描述來說已經足夠長了。作為描述文本,我們使用 sap.m.Text引用資源包屬性的文本控件。我們將屬性minScreenWidth設置為Small,以表明此列在電話上不那麽重要。通過將屬性demandPopin設置為true,我們將告訴表在主列下面顯示這一列。

? Name: 我們的主列有相當大的寬度width來顯示所有的細節。它將始終顯示.

? Status: 狀態並不是那麽重要,所以我們也會將minScreenWidth設置為small, demandPopin設置為true,將它顯示在小屏幕的name字段下面。

? Supplier我們將minScreenWidth設置為Tablet,將demandPopin設置為false,從而完全隱藏了電話設備上的Supplier列。

? Price這一欄總是可見的,因為它包含我們的發票價格。

現在我們將把信息拆分到與上面定義的列匹配的單元格上,而不是以前的ObjectListItem。因此,我們將其更改為具有相同屬性的ColumnListItem控件,但現在使用的是單元格聚合。這裏我們創建五個控件來顯示我們的數據:

?Quantity

A simple sap.m.ObjectNumber control that is bound to our data field.

?Name

A sap.m.ObjectIdentifier controls that specifies the name.

?Status

A sap.m.Text control with the same formatter as before.

?Supplier

A simple sap.m.Text control.

?Price

An ObjectNumber control with the same formatter as the attributes number and numberUnit from the previous steps.

現在我們已經響應性地定義了我們的表,並且可以在減小瀏覽器屏幕大小時看到結果。供應商欄沒有顯示在電話號碼上,這兩欄的數量和狀態將顯示在名稱下面。

webapp/i18n/i18n.properties

...
# Invoice List
invoiceListTitle=Invoices
invoiceStatusA=New
invoiceStatusB=In Progress
invoiceStatusC=Done
columnQuantity=Quantity
columnName=Name
columnSupplier=Supplier
columnStatus=Status
columnPrice=Price
 
# Detail Page
...

當我們減小瀏覽器的屏幕大小或在一個小設備上打開應用程序時,我們可以看到結果。我們將列名和屬性標題添加到i18n文件中。

Conventions

  針對手機、平板電腦和桌面設備的不同屏幕大小優化應用程序。


Parent topic: Walkthrough

Previous: Step 34: Custom Controls

Next: Step 36: Device Adaptation

Related Information

Configuring Responsive Behavior of a Table

UI5-文檔-4.35-Responsiveness