on 06-21-2018 3:55 PM
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!
sap.ui.getCore().setModel(oModel,"uploadData")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you both for your help. Unfortunately neither of these options work for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
sap.ui.getCore(pirTable).setModel(oModel), try if this works
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.