Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 7790

Data Binding for Custom Controls?

$
0
0

Hello,

 

I'm a little bit confused of how to use databinding for custom controls.

I know i can bind a property, as seen here http://help.sap.com/saphelp_uiaddon10/helpdata/en/91/f0f3cd6f4d1014b6dd926db0e91070/content.htm, but how can I map whole arrays?

 

My problem is the following:
I want to create a custom table control in SAPUI5 (as the default one doesn't provide the neccessary options and properties I need), but I can't seem to find an example how to bind "rows".

There has to be a way to do this properly. All I can think of now, and implemented, is, passing the name of the variable in the model...

var x = new my.controls.complex.table({data: "/status"});
var row1 = new my.controls.complex.columnHeaderRow();
...
row1.addColumn(new my.controls.complex.column({text: "", rowspan: "2", colspan: "1", content: "FIRST_COL"}));
...
x.addColumnsRow(row1);
...
x.placeAt("content");

...my JSON/model looks like:

{ "status": [ {"FIRST_COL": "a" , ...}, {"FIRST_COL": "b", ... }, ... ], ... }

(which should translate into /status/0/FIRST_COL, /status/1/FIRST_COL, ... AFAIK)

 

... and then I use this variable name by getting the application-wide model and use the variable passed as key for the model... (please note, this code is just a snippet)

 

    

       var sapCore = sap.ui.getCore();            if (sapCore !== undefined) {             var model = sapCore.getModel().getObject();             if (model === undefined || model == [] || model == null){ } else {              $.each(model, function(idx, item){               $.each(oControl.getColumnsRows(), function(idx, item2) {                $.each(item2.getColumns(), function(idx, item3){                 var content = item3.getContent();                 if (content !== undefined && content != ""){                  outpLine = outpLine + "<td>" + model[idx][content] + "</td>";                 }                });

...which still leaves me with the problem of to get an event to react to re-render on changes within the data model, as well as when there would be just an control-specific model, or just a sub-node within a model etc.

 

So my question is:

Is there a way/best practice to define data binding in a custom control and have a way to react on it, and how to react on data changes within a custom control?

 

 

Thanks & KR
Chris


Viewing all articles
Browse latest Browse all 7790

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>