cancel
Showing results for 
Search instead for 
Did you mean: 
Subscribe

Hello.

I want to adjust the width of the column to match the width of the content, using sap.ui.table.Table.

The controller code is as follows.

		onInit: function () {
			var oTable = this.byId("table");
			oTable.bindRows({
				path: '/BusinessPartnerSet',
				events: {
					dataReceived: this._adjustColumn.bind(this)
				}
			});
		},
		
		_adjustColumn: function () {
			var oTable = this.byId("table");
			oTable.getColumns().forEach((oColumn, index) => {
				oTable.autoResizeColumn(index);
			});
		}

The issue is, at the point of dataRecieved event, contents in the table are not yet available.

As a result, the columns are adjusted to match the width of the title, wihch is sometimes too small to fit all the content in.

Does anybody know which event we can use to adjust columns?

Best regards,

Mio

0 Likes
View Entire Topic
maheshpalavalli
Active Contributor

setTimeout is something you can use or you can try onafterrendering of table

oMyTable.addEventDelegate({
   onAfterRendering: function() {
      // Try resizing here.. if the data is loaded
   }
});
MioYasutake
SAP Champion
SAP Champion
0 Likes

Dear Mahesh,

Thank you for your suggestion. setTimeout worked.

onAfterRendering event was too early to adjust columns, as table contents were not available at this point.

Regards,

Mio

maheshpalavalli
Active Contributor
0 Likes
mioyasutake i just saw the code, and it looks like onAfterRendering will not be triggered, but another event is triggered, it's a private event, so it's risky to use it
oTable.attachEvent("_rowsUpdated", function() {
///					
				}.bind(this));
so for now it looks like setTimeout is on way(which also I don't like it 😄 )BR,Mahesh
MioYasutake
SAP Champion
SAP Champion
0 Likes

Hi Mahesh,

Thanks for your comment.

There doesn't seem to be an official way to implement column optimization.

Regards,

Mio

maheshpalavalli
Active Contributor
0 Likes
mioyasutake, I can't tell for 100 percent that there is no other way, (the only ways i found are the ones that i mentioned here).You could raise an issues in openui5 git, if you want to get expert resolution on this.-Mahesh