cancel
Showing results for 
Search instead for 
Did you mean: 

Table Binding in UI5

MartyMcCormick
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello experts

I'm trying to develop an app where a csv is uploaded and then displayed in a table for review. I have the csv upload working and believe I have json correctly created but no matter what I try I cannot get the data to appear in the table.

Here is my controller:

uploadCSVFile : function(oEvent){ var that = this; var file= oEvent.getParameter("files")[0]; if(file && window.FileReader){ var reader = new FileReader(); reader.onload = function(evn){ var strCSV = evn.target.result; //string in CSV var jsonCSV = that.csvJSON(strCSV); console.log(jsonCSV); var oModel = new sap.ui.model.json.JSONModel(); // Load JSON in model oModel.loadData(jsonCSV); sap.ui.getCore().setModel(oModel); }; reader.readAsText(file); } },

Here is my view:

<Table id="pirTable" items="{uploadData>/}"> <columns> <Column> <Text text="Material"></Text> </Column> <Column> <Text text="Plant"></Text> </Column> <Column> <Text text="MRP Area"></Text> </Column> <Column> <Text text="RType"></Text> </Column> <Column> <Text text="Version"></Text> </Column> <Column> <Text text="Period"></Text> </Column> <Column> <Text text="Period Type"></Text> </Column> <Column> <Text text="Base UoM"></Text> </Column> <Column> <Text text="Quantity"></Text> </Column> <Column> <Text text="MRP Controller"></Text> </Column> </columns> <items> <ColumnListItem> <cells> <Text text="{uploadData>material}"></Text> <Text text="{uploadData>plant}"></Text> <Text text="{uploadData>mrparea}"></Text> <Text text="{uploadData>rtype}"></Text> <Text text="{uploadData>version}"></Text> <Text text="uploadData>period}"></Text> <Text text="{uploadData>periodtype}"></Text> <Text text="{uploadData>baseuom}"></Text> <Text text="{uploadData>quantity}"></Text> <Text text="{uploadData>mrpcontroller}"></Text> </cells> </ColumnListItem> </items> </Table>

And here is the console Log output of the statement:

{"material":"YPIR001","plant":"1710","mrparea":"1710","rtype":"VSF","version":"0","period":"612018","periodtype":"M","baseuom":"PC","quantity":"100","mrpcontroller\r":"1\r"},{"material":"YPIR001","plant":"1710","mrparea":"1710","rtype":"VSF","version":"0","period":"712018","periodtype":"M","baseuom":"PC","quantity":"100","mrpcontroller\r":"1"}]

Thanks!

Accepted Solutions (0)

Answers (3)

Answers (3)

junwu
Active Contributor

sap.ui.getCore().setModel(oModel,"uploadData")

MartyMcCormick
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thank you both for your help. Unfortunately neither of these options work for me.

SergioG_TX
Active Contributor
0 Kudos

if you are able to write your json to the console, then it looks like your json model is an unnamed model.

remove the {uploadData>/} from the items property to bind into the unnamed model --> items.


then for your text columns.. do something like

<Text text="{material}" />

<Text text="{plant}" />

etc

former_member187794
Participant
0 Kudos

sap.ui.getCore(pirTable).setModel(oModel), try if this works