Hi experts,
I would need your help on the following...
I need to be able to dynamically create the columns androws using sap.m.Table.
What I currently have is:
- controller from my master view (list) is catching the event on click and needs to refresh my JS view attached as detail view.
- load data via an ajax call and get value in a JSON format.
so for now I have this code in the controller of my main view:
listTap:function(event){
var selectedId = event.getParameter('listItem').getCustomData()[1].getValue();
this.bus.publish("nav", "to", {
id: event.getParameter('listItem').getCustomData()[0].getValue()
});
var ResultView = this.getView().app.resultDetailPage;
var newModel = new sap.ui.model.json.JSONModel();
// build the data ==> Ajax call
jQuery.ajax({
... // call my backend/local file to get the data
success: function(data, textStatus, jqXHR) { // callback called when data is received
newModel.setData(data); // fill the received data into the JSONModel
},
error: function(jqXHR, textStatus, errorThrown) {
alert("error occurred");
}
});
ResultView.setModel(newModel);
}
As of now my model get's updated correctly... The question is coming :-)
In my detail view (ResultView) in the onInit i want to generate my sap.m.Table and bind the columns and row to the display...
I can't hardcode the columns as they might change depending on the selected item on my master view.
On top of that, as the result is coming from a kind of alv table result, I get the columns and rows to be show in the following format:
{
"columns": [
{
"fieldname": "col_empno",
"coltext": "Employee No.",
"fix_column": "",
"checkbox": "",
"currency": "",
"decimals": 0,
"just": "",
"no_out": "",
"do_sum": ""
}, ..... ==> Other column definition follows
],
"rows": [
{
"col_empno": 1, ... ==> Values for other columns follow this one for each column defined in the "columns" array
}
]
}
I need to display the "coltext" in the column header for each column and then the rows with the values corresponding to each column using the data binding between the model and the view...
I can't seem to have it working...
Can anyone give me a hand with this?
I really need to use the sap.m.Table objects and not the sap.ui.table.Table...
Any idea would be welcome to direct me to the working solution...
If I would be able to get the model of the view I could try to loop at all columns and then add them in the tables then bind the rows to it... but in that case how would I be able to link correclty the value of the cell to the column as the order of the values in the "rows" is not guaranteed...
Thanks a lot in advance!