Skip to Content
0

Dynamic binding of rows in sap.ui.table.Table using XML views

Nov 28, 2016 at 10:55 AM

111

avatar image
Former Member

Hello,

I think this question was asked several times, but it doesn't work in my code.

Does somebody see my mistake or what I´m doing wrong?

I need fully dynamic table (colls and rows). Using the coding below I get the columns but the row data is not displayed.

Could somebody help me?

XML:

<t:Table
 id="table"
 selectionMode="None"
 visibleRowCount="5"
 enableSelectAll="false"
 threshold="15"
 enableBusyIndicator="true"
 columns="{
  	path: 'data>/cols',
  	factory: '.columnFactory'
  	}"
 ariaLabelledBy="title">
 <t:noData>
 <BusyIndicator/>
 </t:noData>
</t:Table>

JS:

onInit: function() {

var cols = [{
	columnName: "123"
	}, {
	columnName: "456"
	}, {
	columnName: "789"
	}];

var rows = [{
	par1: "S",
	par2: "T",
	par3: "C"
	}, {
	par1: "L",
	par2: "",
	par3: "F"
	}, {
	par1: "",
	par2: "Bla",
	par3: "Bla"
	}];

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


oMetaModel.setData({rows: processFlat,
		   cols: cols});


this.getView().byId("table").setModel(oMetaModel,"data");
this.getView().byId("table").bindRows("data>/rows");
},

columnFactory : function(sId, oContext) {
	var tab = this.getView().byId("table");
			
	var colInd = sId.slice(-1);
        var sColumnId = oContext.getModel().oData.cols[colInd].label;
        return new sap.ui.table.Column({           
            label: sColumnId , 
            template: sColumnId, 
            sortProperty: sColumnId, 
            filterProperty: sColumnId});
}

Thank you and regards

Denis

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
avatar image
Former Member Nov 28, 2016 at 02:10 PM
0

I solved the problem, the column name and the parameter name are to be consistent, since it is automatically applied in the path.

var cols = [{
	columnName: "123"
	}, {
	columnName: "456"
	}, {
	columnName: "789"
	}];

var rows = [{
	123: "S",
	456: "T",
	789: "C"
	}, {
	123: "L",
	456: "",
	789: "F"
	}, {
	...
	}];
Share
10 |10000 characters needed characters left characters exceeded