Binding of single aggregation "template" of Element sap.ui.table.Column
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:
- generate Column ( say Col1) using factory function.
- 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!
Hi @bhardwaj-rahul I've created an internal incident 2070177140. The status of the issue will be updated here in GitHub.
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
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. :).
Alright :) I'll close the issue then.