cancel
Showing results for 
Search instead for 
Did you mean: 

Select and bind dynamic columns

0 Kudos

Hi,

I need to be able to create an table dynamically, making the request with $select dynamic and binding the smarttable to only show the fields that were selected. I tried to assign the fields on the select this way "this.getView().byId(sTableId).getBinding().mParameters.select = " on beforeRebindTable and then all others fields make them invisible but i don't think thats a right way to do that.
I wanted the table to render only the fields passed on the select, so when changing for example the fields control, the other's fields from my entity doesn't show

Code examples would be great,

thank you!

Accepted Solutions (0)

Answers (2)

Answers (2)

leonikussmaul
Product and Topic Expert
Product and Topic Expert

Hi,

If you just keep your smart table without setting the initially visible fields and request at least fields, you can then handle the binding in the event handler of the selection change.

<smartTable:SmartTable id="smartTable" entitySet="YourEntitySet" enableAutoBinding="true" tableType="ResponsiveTable" />
onSelectionChange: function() {
// Get the fields that were selected (e.g., from a MultiComboBox or any other control)
var aSelectedFields = this.getSelectedFields(); // Replace this with your logic to get selected fields
var sSelect = aSelectedFields.join(",");
var oSmartTable = this.getView().byId("smartTable"); oSmartTable.setRequestAtLeastFields(sSelect); oSmartTable.setInitiallyVisibleFields(sSelect); oSmartTable.rebindTable();
},
0 Kudos

Hi,

what is that onSelectionchange event?
I tried on beforebindtable event and setting initial fields isn't possible -> "property initiallyVisibleFields cannot be changed after the SmartTable with id application-X is initialised".
And with only the setRequestAtLeastFields the fields doesn't show anyway.

Please note that on every "GO" request it should calculate again the fields to display ( dynamic ), so making that logic onInitilization will not work.

leonikussmaul
Product and Topic Expert
Product and Topic Expert
0 Kudos

onSelectionChange would be fired whenever the filters are changed - it was not clear from your comment what kind of control / logic would be used for that so I left it open.

For me this way has worked but another option would be to instead get the sap.m.Table instance inside the SmartTable -> oSmartTable.getTable() and use the methods of this table to set certain columns as visible/ not visible based on the selected fields.

0 Kudos

Yes, in my case i get the fields from an odata request that will return the fields that would be needed to show.
I already have that logic making the fields invisible but the thing it's for example when I change columns displayed then the fields that i said to remain invisible gets visible etc..

So, I wanted to someway bind the table only with the fields I passed in, so on available columns settings only show that fields I wanted to show. To achieve that i wanted set it on every "GO" request. So, when i get the data, it will check always the fields to show, and my requirement it's that only render that fields in particular!

junwu
Active Contributor
0 Kudos

do you really have this kind of business scenario, that you changed the field property and want it to be reflected immediately?

check if recreating smart table will help.

const smartTable = new sap.ui.comp.smarttable.SmartTable(
('smartTable-id'),
{
entitySet: 'yourEntity',
width: '100%',
enableAutoBinding: true,
tableType: 'ResponsiveTable',
useExportToExcel: false,
showFullScreenButton: true,
useTablePersonalisation: false
}
);
0 Kudos

Hi Jun,

Depreciation area * are the fields that were dynamically changed their name and don't modify their visibility.
in the case of change of fields in the view settings, the fields that i make them invisible in the controller "NetbookValue*" are shown as well due to assign them initial fields on the view. Even modifying the $select request on beforeRebind event, that unwanted fields come in. So at each new request of data ( GO button ) I wanted to build the table ( so unwanted fields will not shown ), or adding/removing the dynamic columns someway and ofcourse in a new request of data i would need to reset or delete the table.

In the case of building the table would be on onGo event? and how I would remove the "old" table to then create a new one?
I'm quite new to sapui5, so in that case I would remove my xml view, and making the view and table in the controller right? But how can I do that? Ok i understand the part to create the table etc ( at what event it will trigger that ?), but i don't understand how i can show that table on the page. Code examples would help a lot.

junwu
Active Contributor
0 Kudos

still not able to understand your scenario....