Table - Defining Column Width
While defining the column width you can use percent values but you should be careful with them. Click to see some traps and tipps.
Z2UI5_CL_SMPC_APP_567
Controls
sap.m
UI5 1.71
The facts
- Repository
- abap2UI5/samples-controls
- Class
Z2UI5_CL_SMPC_APP_567- Source file
z2ui5_cl_smpc_app_567.clas.abap↗- Library
- sap.m
- UI5 entity
sap.m.Table- Demo kit sample
sap.m.sample.TableColumnWidth- SAP's own sample
- running at sdk.openui5.org ↗
- Minimum UI5
- 1.71 — the floor abap2UI5 holds its samples to
- In the playground
- runs in the browser, with no system and nothing installed
Keywords: table, sap.m, tablecolumnwidth, messagestrip, toolbar, title, toolbarspacer, checkbox, column, input, columnlistitem, text
Controls it builds
- sap.m.CheckBox
- sap.m.Column
- sap.m.ColumnListItem
- sap.m.Input
- sap.m.MessageStrip
- sap.m.OverflowToolbar
- sap.m.Table
- sap.m.Text
- sap.m.Title
- sap.m.Toolbar
- sap.m.ToolbarSpacer
- sap.ui.core.mvc.View
Read out of the builder chain by the abap2UI5 linter, not from the category this sample is filed under — which is what makes “which samples build one of these” a question the catalogue can answer at all.
Libraries
Run it here
The sample running, in this page — the app on its own, with no editor over it.
Switch to Playground with this code
Nothing is installed and nothing is sent anywhere: the ABAP is compiled to JavaScript in this browser and runs against abap2UI5 itself.
The ABAP
z2ui5_cl_smpc_app_567.clas.abap — 205 lines
Click a number to link to a line — shift-click for a range.
Read it on GitHub ↗
" @keywords table sap.m tablecolumnwidth messagestrip toolbar title toolbarspacer checkbox column input columnlistitem text
" @summary While defining the column width you can use percent values but you should be careful with them. Click to see some traps and tipps.
CLASS z2ui5_cl_smpc_app_567 DEFINITION PUBLIC.
PUBLIC SECTION.
INTERFACES z2ui5_if_app.
TYPES: BEGIN OF ty_s_product,
name TYPE string,
suppliername TYPE string,
description TYPE string,
END OF ty_s_product.
TYPES ty_t_product TYPE STANDARD TABLE OF ty_s_product WITH EMPTY KEY.
TYPES: BEGIN OF ty_s_column,
width TYPE string,
header TYPE string,
demandpopin TYPE abap_bool,
minscreenwidth TYPE string,
styleclass TYPE string,
END OF ty_s_column.
TYPES ty_t_column TYPE STANDARD TABLE OF ty_s_column WITH EMPTY KEY.
DATA t_products TYPE ty_t_product.
" the two column models: the clone gives its first column width auto, which
" is what makes the first table the correct usage
DATA t_clone TYPE ty_t_column.
DATA t_columns TYPE ty_t_column.
" onCheckBoxSelect: setFixedLayout( selected ? 'Strict' : true )
DATA strict_layout TYPE abap_bool.
PROTECTED SECTION.
DATA client TYPE REF TO z2ui5_if_client.
METHODS view_display.
METHODS model_init.
PRIVATE SECTION.
ENDCLASS.
CLASS z2ui5_cl_smpc_app_567 IMPLEMENTATION.
METHOD z2ui5_if_app~main.
me->client = client.
IF client->check_on_init( ).
model_init( ).
view_display( ).
ELSEIF client->check_on_navigated( ).
view_display( ).
ENDIF.
ENDMETHOD.
METHOD view_display.
DATA(view) = z2ui5_cl_ui5_view_builder=>factory( ).
view->ele( n = `View` ns = `mvc`
)->a( n = `xmlns` v = `sap.m`
)->a( n = `xmlns:l` v = `sap.ui.layout`
)->a( n = `xmlns:core` v = `sap.ui.core`
)->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`
)->tag( `MessageStrip`
)->a( n = `text` v = `Set the width of at least one column to auto or the fixedLayout property of the table to Strict.`
)->a( n = `type` v = `Success`
)->a( n = `class` v = `sapUiSmallMargin`
)->a( n = `showIcon` v = `true`
)->ele( `Table`
)->a( n = `id` v = `table`
)->a( n = `mode` v = `MultiSelect`
" setFixedLayout( selected ? 'Strict' : true ) - the property takes a
" boolean OR the string Strict, so the expression yields both
)->a( n = `fixedLayout` v = |\{= ${ client->_bind( strict_layout ) } ? 'Strict' : true \}|
)->a( n = `items` v = client->_bind( t_products )
)->a( n = `columns` v = client->_bind( t_clone )
)->ele( `headerToolbar`
)->ele( `Toolbar`
)->tag( `Title`
)->a( n = `text` v = `Products (Correct Usage)`
)->a( n = `level` v = `H2`
)->tag( `ToolbarSpacer`
)->tag( `CheckBox`
)->a( n = `text` v = `Strict Layout`
)->a( n = `selected` v = client->_bind( strict_layout )
)->end(
)->end(
)->ele( `columns`
)->ele( `Column`
)->a( n = `width` v = `{WIDTH}`
)->a( n = `styleClass` v = `{STYLECLASS}`
)->a( n = `demandPopin` v = `{DEMANDPOPIN}`
)->a( n = `minScreenWidth` v = `{MINSCREENWIDTH}`
)->a( n = `popinDisplay` v = `WithoutHeader`
)->tag( `Input`
)->a( n = `value` v = `{WIDTH}`
)->a( n = `description` v = `{HEADER}`
)->end(
)->end(
)->ele( `items`
)->ele( `ColumnListItem`
)->a( n = `vAlign` v = `Middle`
)->a( n = `type` v = `Navigation`
)->ele( `cells`
)->tag( `Text`
)->a( n = `text` v = `{NAME}`
)->a( n = `wrapping` v = `false`
)->tag( `Text`
)->a( n = `text` v = `{SUPPLIERNAME}`
)->a( n = `wrapping` v = `false`
)->tag( `Text`
)->a( n = `text` v = `{DESCRIPTION}`
)->a( n = `wrapping` v = `false`
)->end(
)->end(
)->end(
)->end(
)->tag( `MessageStrip`
)->a( n = `text` v = `Do not try to give percent width to all columns even if it reaches 100% total column width.`
)->a( n = `type` v = `Error`
)->a( n = `class` v = `sapUiLargeMarginTop sapUiSmallMargin`
)->a( n = `showIcon` v = `true`
)->ele( `Table`
)->a( n = `mode` v = `MultiSelect`
)->a( n = `items` v = client->_bind( t_products )
)->a( n = `columns` v = client->_bind( t_columns )
)->ele( `headerToolbar`
)->ele( `OverflowToolbar`
)->tag( `Title`
)->a( n = `text` v = `Products (Wrong Usage)`
)->a( n = `level` v = `H2`
)->end(
)->end(
)->ele( `columns`
)->ele( `Column`
)->a( n = `width` v = `{WIDTH}`
)->a( n = `styleClass` v = `{STYLECLASS}`
)->a( n = `demandPopin` v = `{DEMANDPOPIN}`
)->a( n = `minScreenWidth` v = `{MINSCREENWIDTH}`
)->a( n = `popinDisplay` v = `WithoutHeader`
)->tag( `Input`
)->a( n = `value` v = `{WIDTH}`
)->a( n = `description` v = `{HEADER}`
)->end(
)->end(
)->ele( `items`
)->ele( `ColumnListItem`
)->a( n = `vAlign` v = `Middle`
)->a( n = `type` v = `Navigation`
)->ele( `cells`
)->tag( `Text`
)->a( n = `text` v = `{NAME}`
)->a( n = `wrapping` v = `false`
)->tag( `Text`
)->a( n = `text` v = `{SUPPLIERNAME}`
)->a( n = `wrapping` v = `false`
)->tag( `Text`
)->a( n = `text` v = `{DESCRIPTION}`
)->a( n = `wrapping` v = `false` ).
client->view_display( view->stringify( ) ).
ENDMETHOD.
METHOD model_init.
" setSizeLimit(3) on the products model - only the first three rows render
t_products = VALUE #(
( name = `Notebook Basic 15` suppliername = `Very Best Screens`
description = `Notebook Basic 15 with 2,80 GHz quad core, 15" LCD, 4 GB DDR3 RAM, 500 GB Hard Disc, Windows 8 Pro` )
( name = `Notebook Basic 17` suppliername = `Very Best Screens`
description = `Notebook Basic 17 with 2,80 GHz quad core, 17" LCD, 4 GB DDR3 RAM, 500 GB Hard Disc, Windows 8 Pro` )
( name = `Notebook Basic 18` suppliername = `Very Best Screens`
description = `Notebook Basic 18 with 2,80 GHz quad core, 18" LCD, 8 GB DDR3 RAM, 1000 GB Hard Disc, Windows 8 Pro` ) ).
" the controller's oData, and the deepExtend clone whose first width is auto
t_columns = VALUE #(
( width = `30%` header = `Product Name` demandpopin = abap_false minscreenwidth = `` styleclass = `cellBorderLeft cellBorderRight` )
( width = `20%` header = `Supplier Name` demandpopin = abap_false minscreenwidth = `` styleclass = `cellBorderRight` )
( width = `50%` header = `Description` demandpopin = abap_true minscreenwidth = `Tablet` styleclass = `cellBorderRight` ) ).
t_clone = t_columns.
t_clone[ 1 ]-width = `auto`.
ENDMETHOD.
ENDCLASS.
More in sap.m
- Dialog in Custom Within Area — Within area of sap.ui.core.Popup determines where all popups (including dialogs) are posi…
- Dialog with Custom Footer — Dialog with custom footer and support for message popover.
- Message View inside Popover — A sample with Message View inside a Popover.
- Message View inside ResponsivePopover — A sample with Message View inside a ResponsivePopover.
- Popover with NavContainer — You can nest NavContainers in Popovers (and Dialogs) to navigate to further details in pl…
- Table - Breadcrumb — With an InfoToolbar and some crumb logic you can navigate simple hierarchies with a bread…
- Table - ContextualWidth (Static) — This example shows the container-based pop-in behavior. The container has static width.
- Table - Drag and Drop — Shows the different kinds of drag-and-drop capabilities across view boundaries along with…
- Table - Editable — Table with edit/display togglable scenario.
- Table - IColumnHeaderMenu — This example demonstrates an implementation of the IColumnHeaderMenu interface with the s…
- Table - Fixed vs Auto Layout — You can use fixedLayout property to define the layout algorithm to be used for the table…
- Table - Merge Cells — With column duplicate merging, you can improve the display of repeated data. See the effe…
On this page