openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

Binding of single aggregation "template" of Element sap.ui.table.Column

Open bhardwaj-rahul opened this issue 6 years ago • 4 comments

OpenUI5 version: 1.76.0

Browser/version (+device/version): Chrome latest

I want to create dynamic template (to render different controls) with sap.ui.table.Table to be rendered inside sap.ui.table.Column. So, I tried to dynamically create Columns using factory function and then for that column again call a factory function for the template.

Code View:

                                               <t:Table
							rows="{/CountriesCollection}"
							selectionMode="MultiToggle"
							visibleRowCount="7"
							paste="onPaste"
							ariaLabelledBy="title"
							columns="{
								path:'oColModel>/aCols',
								factory: '.colFactory'
							}">
						</t:Table>

Code Controller :

		onInit: function () {
				var countries = [{
					key:'India',
					name:'India'
				},
				{
					key:'Aus',
					name: 'Aus'
				}];
				var oModel = new sap.ui.model.json.JSONModel({
					CountriesCollection: countries,
					country: ''
				});
				this.getView().setModel(oModel);
					var oModel = new sap.ui.model.json.JSONModel({
						aCols: [
							"ABC",
							"DDB"
							]
					});
				this.getView().setModel(oModel, "oColModel");
				
		},
	
		colFactory: function(sId, oContext) {
			var oCol =  new sap.ui.table.Column(sId,{
				label:'TestCol'
			});
			oCol.bindAggregation("template", '', this.cellFactory)
			return oCol;
		},
		cellFactory: function(sId,oContext) {
			var oControl;
			var key = oContext.getProperty('key');
			if (key === 'India') {
				oControl = new sap.m.Input(sId,{
					value: 'Input'
				});
			} else {
				oControl = new sap.m.Text(sId,{
					text: 'Text'
				});
			}
			return oControl;
		}

When I run my code, I receive following error : Binding of single aggregation "template" of Element sap.ui.table.Column#__table0-0 is not supported! -

Is there anyway I can dynamically have different templates ( to render different controls) inside sap.ui.table.Column ?

Steps to reproduce the problem:

  1. generate Column ( say Col1) using factory function.
  2. for column created in step1 (Col1), create factory function for template.

What is the expected result? Have different controls for sap.ui.table.Column

What happens instead? I receive error : Binding of single aggregation "template" of Element sap.ui.table.Column#__table0-0 is not supported!

bhardwaj-rahul avatar Apr 21 '20 11:04 bhardwaj-rahul

Hi @bhardwaj-rahul I've created an internal incident 2070177140. The status of the issue will be updated here in GitHub.

georgimkv avatar Apr 22 '20 14:04 georgimkv

As I understood, you want to have different controls per row in a column. This is not possible. The column can only have one template, which is cloned to all cells of the column. But if there are not too many different controls (performance), you can for example use a VBox as the template. The VBox then contains the controls that you want to use, with their "visible" property bound as per your needs.

Maybe this is what you are looking for? https://jsbin.com/dicapaqobu/edit?html,output

JumpNRun avatar Apr 22 '20 16:04 JumpNRun

hi @JumpNRun ,

Yeah, this is similar to what I wanted. But my template had all different kinds of controls ( like Input, Date, Text, Checkbox, Select etc). I was just wondering how we could create different controls using factory functions in sap.m.Table control but not in sap.ui.table.Table.

Thank you for your response :). I will proceed with this. :).

bhardwaj-rahul avatar Apr 23 '20 12:04 bhardwaj-rahul

Alright :) I'll close the issue then.

JumpNRun avatar Apr 23 '20 13:04 JumpNRun