Hi All,
when i insert data in a table from excel sheet so data is not showing in a last column.
View
<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
controllerName="simple_table.table" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:t="sap.ui.table">
<Page title="Title">
<content>
<Link text="upload" press="onConfirmDialog"/>
<t:Table id ="mytbl" rows="{/}" visibleRowCount="5" width="1281px" >
</t:Table>
</content>
</Page>
</core:View>
Controller
sap.ui.controller("simple_table.table", {
/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* @memberOf simple_table.table
*/
onInit: function() {
var oModel = new sap.ui.model.json.JSONModel();
this.getView().setModel(oModel);
sap.ui.getCore().setModel(oModel);
},
onConfirmDialog: function () {
var that = this;
var dialog = new sap.m.Dialog({
title: 'Upload',
type: 'Message',
icon: 'sap-icon://download',
content: [
new sap.ui.unified.FileUploader({
id: 'fileuploader',
width: '100%',
uploadUrl: 'upload/',
change: function(oEvent) {
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
that.csvJSON(strCSV);
};
reader.readAsText(file);
}
dialog.close();
}
})
],
endButton: new sap.m.Button({
text: 'cancel',
press: function () {
dialog.close();
}
}),
afterClose: function() {
dialog.destroy();
}
});
dialog.open();
},
csvJSON : function(csv){
var lines=csv.split("\n");
var result = [];
var headers=lines[0].split(",");
for(var i=1;i<lines.length;i++){
var obj = {};
var currentline=lines[i].split(",");
for(var j=0;j<headers.length;j++){
obj[headers[j]] = currentline[j];
}
result.push(obj);
}
var columnArr = [];
var oStringResult = JSON.stringify(result);
for( var key in result[0]){
columnArr.push(key);
}
var oFinalResult = JSON.parse(oStringResult.replace(/\\r/g, ""));
sap.ui.getCore().getModel().setProperty("/", oFinalResult);
var tbl = this.getView().byId('mytbl')
var col = tbl.getColumns();
if(col.length > 0){
tbl.removeAllColumns();
}
for(var i=0 ; i< columnArr.length ; i++){
tbl.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: columnArr[i]}),
template: new sap.ui.commons.TextView().bindProperty("text",columnArr[i])
}));
}
/* tbl.bindAggregation("columns","/" , function(sid,oContext){
return new sap.ui.table.Column({
text: oContext.getProperty("Tplnr"), //bound to model
icon: "sap-icon://inbox", //bound to model
toggleOpenState: function(oEvent) {
console.log("Node is opened: "+ oEvent.getParameter("opened"));
}
});
});
*/
},
/**
* Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered
* (NOT before the first rendering! onInit() is used for that one!).
* @memberOf simple_table.table
*/
// onBeforeRendering: function() {
//
// },
/**
* Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here.
* This hook is the same one that SAPUI5 controls get after being rendered.
* @memberOf simple_table.table
*/
// onAfterRendering: function() {
//
// },
/**
* Called when the Controller is destroyed. Use this one to free resources and finalize activities.
* @memberOf simple_table.table
*/
// onExit: function() {
//
// }
});
Output screen
![Capture1.JPG]()
![Capture2.JPG]()
Do you have any solutions ? I appreciate for your help.
Thanks & Regards,
Ayushi