cancel
Showing results for 
Search instead for 
Did you mean: 

Why am I getting same data in all rows?

Former Member
0 Kudos

I have a table to which I am showing data from the model.

when I click on split button, a new row gets added.

Now if I change data in any 1 input field, all the input fields gets updated, and also the SubItem No is remaining same for all the rows, when I add new row the numbering will update for all. don't know what is wrong.

order qty, received qty unit is same for all the rows. posting qty and Batch will be different.

Below is the code I've written for model and to add new row when clicked on split button.

_getModelAndBindData: function() {
        this._aBatchItem = [];
        // first get the global model
        let oBatchItemModel = sap.ui.getCore().getModel("batchItem").getProperty("/");
        console.log(oBatchItemModel);
        oBatchItemModel.Postingquantity = "";

        let SubItemno = parseInt(oBatchItemModel.SubItemno);
        if (SubItemno === 0) {
            oBatchItemModel.SubItemno = 0;
            oBatchItemModel.SubItemno += 1;
        }
        this._aBatchItem.push(oBatchItemModel);
        let itemJsonModel = new JSONModel({
            results: this._aBatchItem
        });
        this.getView().byId("id_BatchSplit_table").setModel(itemJsonModel, "itemJsonModel");
    },

    onBatchSplitButtonPress: function(oEvent) {
        let oTableControlRef = oEvent.getSource().getParent().getParent();
        let oItemJsonModel = oTableControlRef.getModel("itemJsonModel");
        let localData = oItemJsonModel.getProperty("/results");

        this._aBatchItem[0].SubItemno = this._getUniqueSubItemno(oEvent);

        let oNewRow = this._aBatchItem[0];
        localData.push(oNewRow);
        oItemJsonModel.setProperty("/results", localData);
    },
View Entire Topic
junwu
Active Contributor
0 Kudos

seems you are pushing same object again and again.

this._aBatchItem.push(oBatchItemModel);

put the new item in a object, then push

var newItem={}//fill it

then

this._aBatchItem.push(

newItem

);
Former Member
0 Kudos

It worked.

Thank you.