我有一张桌子。但是,我需要向现有表中动态添加新列。我已成功在表中添加了新的列标题,但未能将新单元格添加到表中的当前ColumnListItem中。
任何人都可以帮助我。
以下是我的源代码
View.xml
branch B
Controller.js
<Table id="customerTable" width="auto" items="{path:'customerJSONData>/', sorter: {path: 'CUSTOMER_NAME', descending: false} }"
growing="true" growingScrollToLoad="true">
<columns>
<Column id="nameColumn1">
<Text text="Customer ID" id="nameCustomerID"/>
</Column>
<Column id="nameColumn2">
<Text text="Customer Name" id="nameCustomerName"/>
</Column>
<Column id="nameColumn3">
<Text text="Address Line 1" id="nameAddress1" />
</Column>
<Column id="nameColumn4">
<Text text="Address Line 2" id="nameAddress2" />
</Column>
<Column id="nameColumn5">
<Text text="Private Number" id="namePrivateNumber"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<ObjectIdentifier title="{customerJSONData>CUSTOMER_ID}"/>
<ObjectIdentifier title="{customerJSONData>CUSTOMER_NAME}"/>
<ObjectIdentifier title="{customerJSONData>ADDRESS_LINE_1}"/>
<ObjectIdentifier title="{customerJSONData>ADDRESS_LINE_2}"/>
<ObjectIdentifier title="{customerJSONData>PRIVATE_NUMBER}"/>
</cells>
</ColumnListItem>
</items>
</Table>
CustomerJSON
extColumnHeader = "idExtHeader" + (i+1).toString();
var ExtColumnHeader = new sap.m.Column(extColumnHeader,{header: new sap.m.Label({text:customer_Ext[i].fieldlabel})});
this.getView().byId("customerTable").addColumn(ExtColumnHeader);
var colItems = this.getView().byId("customerTable").getColumns();
var ExtValue = new sap.m.Text("extColumnBodyId",{text:"ProductID"});
colItems.addCell(ExtValue);
答案 0 :(得分:1)
您需要添加具有绑定属性的新列
addNewCol: function(oEvent) {
var oTable = this.byId("customerTable");
var oCol = new sap.m.Column({
label: customer_Ext[i].fieldlabel,
template: "EXT_FLDS/PRINTING_NUM/fieldvalue", //Updated PATH, Update your binding property from customerJSONData model
});
oTable.addColumn(oCol);
}
现有customerJSONData
模型数据
[
{"CUSTOMER_ID":"200","CUSTOMER_NAME":"RF","ADDRESS_LINE_1":"CV","ADDRESS_LINE_2":"5988","PRIVATE_NUMBER":"YY"},
{"CUSTOMER_ID":"80","CUSTOMER_NAME":"UG","ADDRESS_LINE_1":"RT","ADDRESS_LINE_2":"878","PRIVATE_NUMBER":"RF"},
{"CUSTOMER_ID":"789","CUSTOMER_NAME":"GV","ADDRESS_LINE_1":"ED","ADDRESS_LINE_2":"8989","PRIVATE_NUMBER":"FGG"}
]
要添加新的列,模型应具有另外一个属性,即此处newCol
[
{ "CUSTOMER_ID": "200", "CUSTOMER_NAME": "RF", "ADDRESS_LINE_1": "CV", "ADDRESS_LINE_2": "5988", "PRIVATE_NUMBER": "YY", "EXT_FLDS": { "PRINTING_NUM": { "fieldvalue": 11, "fieldlabel": "Printing Number", "uictrl": "sap.m.Input" }, "COUNTRY": { "fieldvalue": "Thailand", "fieldlabel": "Country", "uictrl": "sap.m.ComboBox" } } },
{ "CUSTOMER_ID": "80", "CUSTOMER_NAME": "UG", "ADDRESS_LINE_1": "RT", "ADDRESS_LINE_2": "878", "PRIVATE_NUMBER": "RF", "EXT_FLDS": { "PRINTING_NUM": { "fieldvalue": 11, "fieldlabel": "Printing Number", "uictrl": "sap.m.Input" }, "COUNTRY": { "fieldvalue": "Thailand", "fieldlabel": "Country", "uictrl": "sap.m.ComboBox" } } },
{ "CUSTOMER_ID": "789", "CUSTOMER_NAME": "GV", "ADDRESS_LINE_1": "ED", "ADDRESS_LINE_2": "8989", "PRIVATE_NUMBER": "FGG", "EXT_FLDS": { "PRINTING_NUM": { "fieldvalue": 11, "fieldlabel": "Printing Number", "uictrl": "sap.m.Input" }, "COUNTRY": { "fieldvalue": "Thailand", "fieldlabel": "Country", "uictrl": "sap.m.ComboBox" } } }
]
注意:假设
NewProperty
存在于绑定customerJSONData
模型中。