简体   繁体   English

SAPUI5将新列和值添加到现有表

[英]SAPUI5 Add new column and value to existing table

I am having a table. 我有一张桌子。 However, i need to add new column dynamically to my existing table. 但是,我需要向现有表中动态添加新列。 I successfully added a new column header in my table, but I failed to add new cells to my current ColumnListItem in my table. 我已在表中成功添加了新的列标题,但未能将新单元格添加到表中的当前ColumnListItem中。

Anyone can help me. 任何人都可以帮助我。

The following is my source code 以下是我的源代码

View.xml view.xml用

<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>

Controller.js Controller.js

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); 

CustomerJSON CustomerJSON

[
   {
        "CUSTOMER_ID" : "C001",
        "CUSTOMER_NAME": "Weng Fong Sdn Bhd",
        "ADDRESS_LINE_1": "Tai Rai Bong",
        "ADDRESS_LINE_2": "Hatyai",
        "PRIVATE_NUMBER" : "10001",
        "EXT_FLDS" : {
            "PRINTING_NUM": {
              "fieldvalue": 12,
              "fieldlabel": "Printing Number",
              "uictrl": "sap.m.Input"
            },
            "COUNTRY": {
              "fieldvalue": "Thailand",
              "fieldlabel": "Country",
              "uictrl": "sap.m.ComboBox"
            }
        }
]

You need to add the new column with binding property 您需要添加具有绑定属性的新列

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);
}

Existing customerJSONData Model Data 现有的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"}
]

For adding the new Column the model should have one more property ie newCol here 为了添加新的列,模型应具有一个以上的属性,即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" } } }
]

Note: Assuming NewProperty exist in the binding customerJSONData model. 注意:假设绑定的customerJSONData模型中存在NewProperty

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM