cancel
Showing results for 
Search instead for 
Did you mean: 

how to bind rows with dynamic json data?

tridwip
Participant
0 Kudos

I have tried this

var oTable= this.getView().byId("tstable");

var date= this.getView().byId("DP1").getValue();

var to = this.getView().byId("to").getValue();

var typ = this.getView().byId("typ").getValue();

var frm = this.getView().byId("frm").getValue();

var prj = this.getView().byId("prj").getValue();

var des = this.getView().byId("des").getValue();

var jModel= new sap.ui.model.json.JSONModel();

var data = {d: {

date: date,

from: "",

to: "",

type:typ,

customer: "",

project: "",

internal: "",

description: "" }};

jModel.setData(data);

oTable.setModel(jModel);

oTable.bindRows("/data"); },

////////////////////

the error in the console is "oTable.bindRows is not a function"

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Is this sap.m.Table or sap.ui.table.Table?

tridwip
Participant
0 Kudos

its a .m table

former_member340030
Contributor
0 Kudos

Hi Tridwip Das

If its sap.m table than there is no method known as bindRows it has bindItems ... Actually sap.m.table is designed as list which has the aggregation items not rows where as the sap.ui.table is designed as proper tables with rows and columns both as aggregations .. please refer api reference of table : https://sapui5.hana.ondemand.com/#/api/sap.m.Table

Tip :

And also a tip for you after seeing your code in the query : don't get values the way you are doing currently like for getting date you are getting the value of the control date (this.getView.byId("DP1")) instead of that use models (json model) ..

Through models you will always get the updated values whereas getting values by control id will give you the value attach to the control which will be static even if the values gets changed ..

Thanks

Viplove khushalani

tridwip
Participant
0 Kudos

thank you sir. yet I have another question about this table matter. may I ask? Thank you!

tridwip
Participant
0 Kudos

Actually sir I have some input fields through which user would input values and the same should be written in table. It is a timesheet table and thats why I need to take input from users. The problem now is that the entered values are replacing but not concatenating to rows.

tridwip
Participant
0 Kudos

tab.png I need to update those rows not replace

Answers (2)

Answers (2)

Sharathmg
Active Contributor

You must be using the sap.m.table. You need to use bindItems and not bindRows.

Joseph_BERTHE
Active Contributor
0 Kudos

uhm, your JSon is not rigth, it is not an Array 😉 Furthermore, the path on your Binding is wrong it should be this :

oTable.bindRows("/"); },

If you do not want to modify your binding, your JSon should be this :

{ data : [ { date : '', from : '', ...}, { date : '', from : '', ...}, ... ]}

Regards,