Skip to Content
Technical Articles

Fiori Element List Report – Adjust column size automatically

You may know that ALV columns width can be adjusted automatically depending on the content size :

This is a cool feature that is unfortunately not available in List Report Fiori Element. There is an option that is activated by default but the behavior is different : SAPUI5 Documentation

The column width is defined according to element theorical length, not the actual length of the content (please note that I’m focusing on List Report in Gridtable mode (not reponsive table).

See example below :

 

 

To reproduce ALV behavior, you will have to implement an extension to your fiori element.

1. Declare the controller extension in the manifest.json

		"extends": {
			"extensions": {
				"sap.ui.controllerExtensions": {
					"sap.suite.ui.generic.template.ListReport.view.ListReport": {
						"controllerName": "<your_namespace>.<your_app_name>.ext.controller.ListReportExt"
					}
				}
			}
		},

2. Add the controller file to your app

3. Add the code below to your controller

sap.ui.controller("<your_namespace>.<your_app_name>.ext.controller.ListReportExt", {

	onInit: function (oEvent) {

		if (!this._sIdPrefix) {
			this._sIdPrefix =
				"<your_namespace>.<your_app_name>::sap.suite.ui.generic.template.ListReport.view.ListReport::<ENTITY_NAME>--";
		}

	},

	onAfterRendering: function (oEvent) {

		var oContentTable = this.byId(this._sIdPrefix + "GridTable");
		oContentTable.attachBusyStateChanged(this._onBusyStateChanged);

	},

	_onBusyStateChanged: function (oEvent) {

		var bBusy = oEvent.getParameter("busy");
		if (!bBusy && !this._bColumnOptimizationDone) {
			var oTable = oEvent.getSource();
			var oTpc = new sap.ui.table.TablePointerExtension(oTable);
			var aColumns = oTable.getColumns();
			for (var i = 0; i < aColumns.length; i++) {
				var iColumn = aColumns.length - i - 1;
				oTpc.doAutoResizeColumn(iColumn);
			}
		}

		//This line can be commented if you want the columns to be adjusted on every scroll
		//this._bColumnOptimizationDone = true;

	}

});

This post helped me : Stackoverflow

4. And voilà !

 

 

If someone knows a way to do this without extension please let me know in the comment section.

 

 

 

 

2 Comments
You must be Logged on to comment or reply to a post.
  • Thank you,

    It works, but after click on setting button, either cancel or ok, the columns are back to original.

    How do we achieve auto width after settling buttons click.

     

    Sai.