In this step, we improve the responsiveness of our app. SAPUI5 applications can be run on phone, tablet, and desktop devices and we can configure the application to make best use of the screen estate for each scenario. Fortunately, SAPUI5 controls like the sap.m.Table already deliver a lot of features that we can use.
You can view and download all files in the Explored app in the Demo Kit under Walkthrough - Step 35.
<mvc:View controllerName="sap.ui.demo.wt.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"> <Text text="{i18n>columnQuantity}"/> </Column> <Column> <Text text="{i18n>columnName}"/> </Column> <Column minScreenWidth="Small" demandPopin="true"> <Text text="{i18n>columnStatus}"/> </Column> <Column minScreenWidth="Tablet" demandPopin="false"> <Text text="{i18n>columnSupplier}"/> </Column> <Column hAlign="End"> <Text text="{i18n>columnPrice}"/> </Column> </columns> <items> <ColumnListItem type="Navigation" press="onPress"> <cells> <ObjectNumber number="{invoice>Quantity}" emphasized="false"/> <ObjectIdentifier title="{invoice>ProductName}"/> <Text text="{ path: 'invoice>Status', formatter: '.formatter.statusText' }"/> <Text text="{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>
We exchange the list with a table simply by replacing the tag <List> with <Table>. The table has a built-in responsiveness feature that allows us to make the app more flexible. The table and the list share the same set of properties so we can simply reuse these and also the sorter.
Quantity
This column will contain a short number, so we set the alignment to End (which means "right" in LTR languages) and the width to 4em which is long enough for the column description. As a description text we use a sap.m.Text control that references a property of the resource bundle. We set the property minScreenWidth to Small to indicate that this column is not so important on phones. We will tell the table to display this column below the main column by setting the property demandPopin to true.
Name
Our main column that has a pretty large width to show all the details. It will always be displayed.
Status
The status is not so important, so we also display it below the name field on small screens by setting minScreenWidth to small and demandPopin to true
Supplier
We completely hide the Supplier column on tablet and phone devices by setting minScreenWidth to Tablet and demandPopin to false.
Price
This column is always visible as it contains our invoice price.
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.
Now we have defined our table responsively and can see the results when we decrease the browsers screen size. The Supplier column is not shown on tablet sizes and the two columns Quantity and Status will be shown below the name.
# App Descriptor appTitle=Hello World appDescription=A simple walkthrough app that explains the most important concepts of SAPUI5 # Hello Panel showHelloButtonText=Say Hello helloMsg=Hello {0} homePageTitle=Walkthrough helloPanelTitle=Hello World openDialogButtonText=Say Hello With Dialog dialogCloseButtonText=Ok # Invoice List invoiceListTitle=Invoices invoiceStatusA=New invoiceStatusB=In Progress invoiceStatusC=Done columnQuantity=Quantity columnName=Name columnSupplier=Supplier columnStatus=Status columnPrice=Price # Detail Page detailPageTitle=Walkthrough - Details ratingConfirmation=You have rated this product with {0} stars # Product Rating productRatingLabelInitial=Please rate this product productRatingLabelIndicator=Your rating: {0} out of {1} productRatingLabelFinal=Thank you! productRatingButton=Rate
We add the column names and the attribute titles to our i18n file.
We can see the results when we decrease the browser's screen size or open the app on a small device.
Optimize your application for the different screen sizes of phone, tablet, and desktop devices.