The sap.ui.comp.smarttable.SmartTable control is used to create different types of tables based on OData metadata. The control allows the user to define personalized table settings.
The frequently asked questions section aims to answer the basic questions that may occur when using the SmartTable control.
For more information about this control, see the API Reference in the Demo Kit and the sample in the Explored app in the Demo Kit.
For more information about annotations for this control, see the API Reference in the Demo Kit.
The SmartTable control is a wrapper control around any SAPUI5 table. The control analyzes the $metadata document of an OData service and renders a table for a specific entitySet.
The control allows the consuming application to build list patterns based on OData services in an efficient and consistent way and thus makes it easy for the user to create tables without much effort. For example, the control enables the automatic creation of columns.
The consuming application can overwrite the OData default information. The SmartTable control offers you additional built-in features, such as a row count and an export to a spreadsheet application.
VariantManagement
SmartFilterBar
P13nDialog
For more information about the various smart controls, see sap.ui.comp.
When using SmartTable with an internal responsive table, you can set the demandPopin property to true. This property renders columns that exceed the space available on the screen by displaying popins.
SmartTable checks the custom data section for the columns and reads the columnIndex attribute to determine when the columns that are defined in the XML view are rendered.
If you want to show and follow navigationProperty fields for EntityType, the SmartTable control automatically performs a $expandoperation for these fields.
Question
How can I enable personalization for columns I add in the XML view in the SmartTable control?
Answer
You can specify custom data for the personalization of the columns in your table as shown in the examples.
Example 1 for a normal aggregation:
#!xml <table:AnalyticalColumn id="Ledger" hAlign="Left" minScreenWidth="Tablet" demandPopin="true"> <table:customData> <core:CustomData key="p13nData" value='\{"columnKey": "Ledger","sortProperty": "Ledger", "filterProperty": "Ledger", "type":"numeric"}'/> </table:customData> <Label text="Ledger"/> <table:template> <Text text="{Ledger}" /> </table:template> </table:AnalyticalColumn>
Example 2 for use of the shortcut notation of SAPUI5 in the namespace:
View namespace part: xmlns:customData="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1"
#!xml <table:AnalyticalColumn id="CompanyCode" hAlign="Left" minScreenWidth="Tablet" demandPopin="true" sortProperty= "CompanyCode" customData:p13nData='\{"columnKey": "CompanyCode","sortProperty": "CompanyCode", "filterProperty": "CompanyCode", "type":"numeric", "maxLength":"4"}'> <Label text="Company Code" /> <table:template> <Text text="{CompanyCode}" /> </table:template> </table:AnalyticalColumn>
In the p13nData object, you can specify the following properties:
A unique key used to save, retrieve, or apply personalization for a column.
Sorts the table based on the column specified; OData model property name must be used.
This property is similar to the table column property.
Filters the table with the condition that has been defined; OData model property name must be used.
This property is similar to the table column property.
Determines the type of a control; its value can be either date, numeric, or empty string. The control will be switched accordingly.
Numeric value to restrict number of entries in input fields
Numeric value for precision
Numeric value for scale
Question
Why do I not see data for my manually added column in the XML view? And why do I get an error "Select at least one column to perform the search" even though I have added several columns manually to the sap.m.Table inside the SmartTable control?
Answer
You need to specify custom data with at least one leadingProperty for the table/columns without a leadingProperty available in the control itself so the SmartTable control can fetch data correctly.
#!xml <Column > <customData> <core:CustomData key="p13nData" value='\{"columnKey": "Id","leadingProperty": "Id","sortProperty": "Id","filterProperty": "Id"}'/> </customData> <Text text="Sales Order" /> </Column>
Without this, the SmartTable control cannot recognize the column.
Question
How do I create and pass a search query ($search="foo" ) when using the SmartTable control?
Answer
Use the beforeRebindTable event and implement this manually.
#!js
onBeforeRebindTable: function(oEvent) { var
mBindingParams = oEvent.getParameter( "bindingParams" );
mBindingParams.parameters[ "custom" ] =
{ "search-focus" :
sBasicSearchFieldName, // the name of the search
field "search" :
sBasicSearchText // the search text
itself! }; }
This will then be used internally when creating the table binding.
Question
How do I get data for custom columns (icons, formatters etc.) that are not present in the columns/binding (select = 'ColA,ColB,foo,bar') of the SmartTable control?
Answer
Use the beforeRebindTable event and implement this manually.
#!js onBeforeRebindTable: function(oEvent) { var oBindingParams = oEvent.getParameter( "bindingParams" ); if (oBindingParams.parameters.select.search( "SomeIconCode" ) < 0) { oBindingParams.parameters.select += ",SomeIconCode" ; } }
This will then be used internally when creating the table binding.
Question
I would like to pass my own custom sorters, filters, and binding parameters when binding the table data in the SmartTable control. How do I do this?
And how can I have my own binding implementation for the SmartTable control?
Answer
You can modify the array of filters before binding is triggered in the SmartTable control by listening to the beforeRebindTable event.
To enable this, your code should look like this:
#!xml <smartTable:SmartTable entitySet="LineItemsSet" beforeRebindTable="onBeforeRebindTable"…
You can now get the list of filters and sorters to be used in table binding using the following:
#!js onBeforeRebindTable: function(oEvent) { var mBindingParams = oEvent.getParameter("bindingParams"); var aFilters = mBindingParams.filters
With this, you need to set back the value to mBindingParams.filters, and you can pass a new filter array as well.
In some exceptional cases, you can set mBindingParams.preventTableBind="true" to prevent table binding from taking place (optional) and do the binding at a later point in time. This is shown in the following method:
#!js someMethod: function() { //get the smartTable and call the method rebindTable() oSmartTable.rebindTable(); }
Question
How do I add custom toolbar buttons in the SmartTable control?
Answer
You can do this using the customToolbar aggregation, as shown below:
#!xml <smartTable:SmartTable id="ItemsST" entitySet="Items" ... <smartTable:customToolbar> <OverflowToolbar design="Transparent"> <ToolbarSpacer/> <Button text="Test"/> <Button text="Click me!"/> </OverflowToolbar> </smartTable:customToolbar>
If you use the OverflowToolbar, the toolbar will also be responsive.