on 06-01-2015 4:23 PM
Hi All,
I have a form in which there are 10 fields in which i am taking input from user and as soon as user click on add button i am adding all those 10 field values in the table which have associated columns for each field. As soon as i add 11th time application shows me following error.
Cannot read property 'getCells' of undefined
I dont understand why it is happening
Please guide.
regards
i have made follwing changes in my code and my problem get resolved
if(trCount>0){
var lastLineNo = aData[trCount-1]["POSNR"];
lineItemNo = oIntegerFormat.parse(lastLineNo.toString()) + 10;
console.log(lineItemNo);
//lineItemNo = oIntegerFormat.parse(oTable2.getRows()[trCount-1].getCells()[15].getValue()) + 10;
}
The commented out line was giving error on getCells() method i dont understand why, i just removed this line and played in the data array and my problem get resolved.
Thanks Robin for your support your discussion give me new ways and thanks to all others too who tried to resolve my issue
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi muhammad,
Please share the code so it will be easy to understand.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is my button code fragment
var oBT_SO_AddItem = new sap.ui.commons.Button("oBT_SO_AddItem" , {
text: "Add Item",
icon: "images/AddRecord.png",
press: function(e) {
if (!oController.validateDetailFields())
return;
AddItemInDetailTable();
}
});
and this my addition logic
function AddItemInDetailTable(){
var aData = [];
var trCount = oTable2.mBindingInfos.rows.binding.iLength;
if(trCount>0)
for(var x = 0; x < trCount; x++){
if (x==10)
console.log(x);
aData.push({
MATNR : oTable2.getRows()[x].getCells()[0].getValue(),
ARKTX : oTable2.getRows()[x].getCells()[1].getValue(),
VKAUS : oTable2.getRows()[x].getCells()[2].getValue(),
DIA : oTable2.getRows()[x].getCells()[3].getValue(),
SPH : oTable2.getRows()[x].getCells()[4].getValue(),
CYL : oTable2.getRows()[x].getCells()[5].getValue(),
ZADD : oTable2.getRows()[x].getCells()[6].getValue(),
KWMENG : oTable2.getRows()[x].getCells()[7].getValue(),
NETPR : oTable2.getRows()[x].getCells()[8].getValue(),
ZEXCH : oTable2.getRows()[x].getCells()[9].getValue(),
ZREASON : oTable2.getRows()[x].getCells()[10].getValue(),
NETWR : oTable2.getRows()[x].getCells()[11].getValue(),
VRKME : oTable2.getRows()[x].getCells()[12].getValue(),
OLDQTY : oTable2.getRows()[x].getCells()[13].getValue(),
PROQTY : oTable2.getRows()[x].getCells()[14].getValue(),
POSNR : oTable2.getRows()[x].getCells()[15].getValue(),
AUFLG : oTable2.getRows()[x].getCells()[16].getValue()==""?"PUT":oTable2.getRows()[x].getCells()[16].getValue(),
WERKS : oTable2.getRows()[x].getCells()[17].getValue(),
});
}
var lineItemNo = 10;
if(trCount>0){
lineItemNo = oIntegerFormat.parse(oTable2.getRows()[trCount-1].getCells()[15].getValue()) + 10;
oTable2.unbindRows();
}
var oModel1 = new sap.ui.model.json.JSONModel();
var oMV_SO_LensAmnt = oIntegerFormat.parse(oTF_SO_Quantity.getValue()) * oFloatFormat.parse(oTF_SO_LensPric.getValue()) + oFloatFormat.parse(oTF_SO_ExtraChg.getValue());
aData.push(
{
MATNR : sap.ui.getCore().byId("oTF_SO_Var_Code").getValue(),
ARKTX : oCB_SO_LensType.getLiveValue(),
VKAUS : oCB_SO_LensSide.getValue(),
DIA : oCB_SO_LensSize.getLiveValue(),
SPH : oCB_SO_Lens_SPH.getLiveValue(),
CYL : oCB_SO_Lens_CYL.getLiveValue(),
ZADD : oCB_SO_Lens_ADD.getLiveValue(),
KWMENG : oTF_SO_Quantity.getValue(),
NETPR : oTF_SO_LensPric.getValue(),
ZEXCH : oFloatFormat.parse(oTF_SO_ExtraChg.getValue()).toFixed(2),
ZREASON : oTF_SO_ReasonEC.getValue(),
NETWR : oMV_SO_LensAmnt.toFixed(3),
VRKME : oCB_SO_LensUnit.getSelectedKey(),
OLDQTY : oTF_SO_Quantity.getValue(),
PROQTY : oTF_SO_Quantity.getValue(),
POSNR : lineItemNo,
AUFLG : "POST",
WERKS : oCB_SO_DelvSite.getSelectedKey()
}
);
oModel1.setData({modelData : aData});
oTable2.setModel(oModel1);
oTable2.bindRows("/modelData");
var otfnv_totQty = sap.ui.getCore().byId("oTF_NV_TotQty");
var otfnv_totVal = sap.ui.getCore().byId("oTF_NV_TotVal");
if(otfnv_totQty.getValue()=="")
otfnv_totQty.setValue("0");
if(otfnv_totVal.getValue()=="")
otfnv_totVal.setValue("0");
var total_qty = oIntegerFormat.parse(otfnv_totQty.getValue()) + oIntegerFormat.parse(oTF_SO_Quantity.getValue());
var total_val = oFloatFormat.parse(otfnv_totVal.getValue()) + oFloatFormat.parse(oMV_SO_LensAmnt.toFixed(3));
otfnv_totQty.setValue(total_qty);
otfnv_totVal.setValue(total_val);
//.
oCB_SO_LensType.focus();
}
Error Description
Uncaught TypeError: Cannot read property 'getCells' of undefined
at eval (eval at evaluate (unknown source), <anonymous>:1:21)
at Object.InjectedScript._evaluateOn (<anonymous>:895:55)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:828:34)
at Object.InjectedScript.evaluateOnCallFrame (<anonymous>:954:21)
at AddItemInDetailTable (http://localhost:52125/Deopti_Order_Stock/deopti/StockOrder.view.js:820:11)
at sap.ui.commons.Button.press (http://localhost:52125/Deopti_Order_Stock/deopti/StockOrder.view.js:468:9)
at a.fireEvent (http://localhost:52125/Deopti_Order_Stock/resources/sap-ui-core.js:135:59661)
at a.fireEvent (http://localhost:52125/Deopti_Order_Stock/resources/sap-ui-core.js:144:121162)
at null.firePress (http://localhost:52125/Deopti_Order_Stock/resources/sap-ui-core.js:144:40628)
at B.onclick (http://localhost:52125/Deopti_Order_Stock/resources/sap/ui/commons/library-preload.json/sap/ui/commo...)
you are correct i recently made this change in it
var aData = [];
var tableModel = oTable2.getModel();
var table_Data = tableModel.getData();
var trCount = oTable2.mBindingInfos.rows.binding.iLength;
if(trCount>0)
aData = table_Data.modelData;
and removed the for loop but problem is still there
Regards
No, what I mean is, why are you accessing your table in the first place? Why not just access your model directly?
After all, SAPUI5 is a model-driven framework, and you should avoid accessing UI controls directly as much as possible..
For instance:
var tableModel = oTable2.getModel();
var tableData = tableModel.getData();
var someData = {
MATNR : "somevalue",
ARKTX : "etc",
//etc
}
tableData.push(someObject);
tableModel.setData(tableData);
will add a new object 'someObject' to your table data, and it will be visible as a new row in your table (provided this object has the same signature as the other data objects in your model)
Dear Robin,
as far as i understand you are saying that instead of adding data directly into any control add into the model, and i think this is what i am doing, if you see the Add AddItemInDetailTable method i am reteriving the old records of the table into an array and then adding new record in that array and again setting the model with the control with new set of records. please eloborate a little how should i do it if you feel that there could be some other better way to do this.
Thx and Regards
Let's say your table is bound to a model property "/somedata", which holds an array of objects which are visible in your table.
You then simply do:
var aData = this.getView().getModel().getProperty("/somedata");
aData.push(someObject);
this.getView().getModel().setProperty("/somedata", aData);
that's it, no need to reference any table or other UI element.
Just use the model's getProperty / setProperty methods for manipulating data
ok let me try it then i will getback to you if i get fail... thx again
I tried the suggested way in the following manner
var oBT_SO_AddItem = new sap.ui.commons.Button("oBT_SO_AddItem" , {
text: "Add Item",
icon: "images/AddRecord.png",
press: function(e) {
if (!oController.validateDetailFields())
return;
//AddItemInDetailTable();
var aData=[];
aData = this.getView().getModel().getProperty("/modeldata");
aData.push(
{
MATNR : sap.ui.getCore().byId("oTF_SO_Var_Code").getValue(),
ARKTX : oCB_SO_LensType.getLiveValue(),
VKAUS : oCB_SO_LensSide.getValue(),
DIA : oCB_SO_LensSize.getLiveValue(),
SPH : oCB_SO_Lens_SPH.getLiveValue(),
CYL : oCB_SO_Lens_CYL.getLiveValue(),
ZADD : oCB_SO_Lens_ADD.getLiveValue(),
KWMENG : oTF_SO_Quantity.getValue(),
NETPR : oTF_SO_LensPric.getValue(),
ZEXCH : oFloatFormat.parse(oTF_SO_ExtraChg.getValue()).toFixed(2),
ZREASON : oTF_SO_ReasonEC.getValue(),
NETWR : oMV_SO_LensAmnt.toFixed(3),
VRKME : oCB_SO_LensUnit.getSelectedKey(),
OLDQTY : oTF_SO_Quantity.getValue(),
PROQTY : oTF_SO_Quantity.getValue(),
POSNR : lineItemNo,
AUFLG : "POST",
WERKS : oCB_SO_DelvSite.getSelectedKey()
}
);
this.getView().getModel().setProperty("/modeldata", aData);
and received following message
Uncaught TypeError: this.getView is not a function
Hi Muhammad
It is hard to tell without know what you have done. There are many ways to do this.
Here is one
-D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.