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
RaminS
Active Participant
0 Likes

SAP should really provide an event after data is loaded into the table, so resizing columns can be done. Without this Grid Tables are pretty much useless. Having to manually press a Resize button every time data is loaded is not good user experience.

I thought beforeRebindTable event would be that event, but it doesn't seem to work, like all other events it seems to be too early.

Has anyone had any luck with beforeRebindTable?

Kishannaicker
Participant
0 Likes

Since the smarttable directly reads data from odata it is usually not possibly to read the data bound to the table unless we access the inner table. In this case "events parameter comes to the rescue.

You can add change, datarequested, datareceived, attachdatastatechange events to the beforerebindtable/beforerebindtableextension (if its a list report) method

onBeforeRebindTableExtension: function (event) {
      
        event.getParameters()["bindingParams"].events = {
            "dataRequested":function(er)
            {
               
            },
            "dataReceived": function (ec) {

ec.getParameter("data")  //this will give the table resultset
}