cancel
Showing results for 
Search instead for 
Did you mean: 

RowRepeator event for reading current Row

former_member220853
Participant
0 Kudos

Dear All

I have created a sample Rowrepeator example. Issue now which I am facing is that I am not able to detect which row I am in (Even after I added radioButton in each row). My requirement is to get current index of the data set and capture that index in select event of radio button (or any control per se)

Has anyone tried that, please help if you are succesful

I am posting my code here

/**
* app.js
**/

// mute logging
jQuery.sap.log.setLevel(jQuery.sap.log.Level.ERROR);

// init main view
sap.ui.localResources("training");
var mainview = sap.ui.view({
id: "shell",
viewName: "training.shell",
type: sap.ui.core.mvc.ViewType.JS
});
mainview.placeAt("content");


// add dummy content to shell
var oShell = sap.ui.getCore().byId("main-shell");
var oButton = new sap.ui.commons.Button({
text: "Click me",
press: function(oEvent) {
  alert('You clicked the button labeled "'
   + this.getText() + '"');
}
})

//create test data
var dataObject = { data : [{index:0, level: "Warning", description: "HAL: I'm sorry, Dave. I'm afraid I can't do that."},
        {index:1, level: "Warning", description: "Windows Boot Manager has encountered a problem."},
        {index:2, level: "Error", description: "Failwhale: Twitter is over capacity"},
        {index:3, level: "Success", description: "Jun 25 12:20:47 pc1h kernel: lp0 on fire"},
        {index:4, level: "Error", description: "Software failure. Press left mouse button to continue. Guru Meditation #00000004,#0000AACB."},
        {index:5, level: "Error", description: "[root@localhost root]# Kernel Panic"},
        {index:6, level: "Error", description: "That does not compute."},
        {index:7, level: "Warning", description: "404 File not found. Stop messing with the URL."},
        {index:8, level: "Success", description: "Blue Screen of Death."}]
};

                   //create JSON model
                   var oModel = new sap.ui.model.json.JSONModel();
                   oModel.setData(dataObject);
                   sap.ui.getCore().setModel(oModel);


var row = new sap.ui.commons.layout.MatrixLayoutRow();


this.matrix = new sap.ui.commons.layout.MatrixLayout({
id : "theMatrix"
});

var control = new sap.ui.commons.TextView();

control.bindProperty("text", "level");
var cell = new sap.ui.commons.layout.MatrixLayoutCell();
//create the template control that will be repeated and will display the data
var oRowTemplate = new sap.ui.commons.Message("rowTemplate", {
    text : "{description}",
    type : "{level}"
});


var label = new sap.ui.commons.Label({
text : "hello"
});

var radioButton = new sap.ui.commons.RadioButton({  
  enabled:true,
  select :function() {
   var data = oModel.getProperty('data');
   var array = data[0];
   var len = array.length;
   alert('Hello'+radioButton.getText());

//  WANT TO CAPTURE CURRENT INDEX OF DATA SET HERE 
   for (var i=0;i<array.length;i++) {
    alert('This is '+array[i]);
   }
  }
  }
);


var rowRepeator = new sap.ui.commons.RowRepeater({
currentPage : 1
});

cell.addContent(label);
cell.addContent(control);
radioButton.setText("Rama");
cell.addContent(radioButton);
row.addCell(cell);
this.matrix.addRow(row);


//sap.ui.getCore().setModel(dataModel);


//rowRepeator.addRow(this.matrix);
//rowRepeator.addRow(this.matrix);

rowRepeator.bindRows("/data",this.matrix);
oShell.setContent(rowRepeator);

Accepted Solutions (1)

Accepted Solutions (1)

former_member220853
Participant
0 Kudos

Was able to resolve it myself. 

Former Member
0 Kudos

Hi Gaurav,

Great that you resolved the problem yourself, could you please take 5 minutes to share the solution with the rest of the community? It might be helpful to someone else in the future.

Thanks,

Simon

Answers (2)

Answers (2)

0 Kudos

Hi,

I tried to read the value of a property from the returned collection with the below code

var oModel = new sap.ui.model.odata.ODataModel("http://HOSTNAME:PORT/SERVICE/COLLECTION");

var test = oModel.getProperty("<PropertyName>");

But I am not able to get the value in the variable "test"

Can somebody help.

Thanks,

Harish

Former Member
0 Kudos

Dear Sai..

you have to give the path in getProperty with index !!

dataObject = {};

dataObject.data = [];

       for(var n = 1; n <= 100; n++) {

                  dataObject.data.push( { lastName:"LastName"+ n, name:"Name" + n, src:"images/persons/male.jpg", country: "DE", href: "http://www.sap.com" } );

            }

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

sap.ui.getCore().setModel(model, 'namen');

 

var name = model.getProperty("/data/4/lastName");

//result is LastName4

former_member220853
Participant
0 Kudos

Sharing the code which helped me getting current element of rowrepeator

var radioButton = new sap.ui.commons.RadioButton({  
  enabled:true,

  select :function(oEvent) {
   var data = oModel.getProperty('data');
   var array = data[0];
   var len = array.length;
  var id = oEvent.getSource().getId();
  //alert(data);
  //alert(id);  
  var idRepeater = id.split("__").reverse()[0];
  alert(idRepeater);   
  control = sap.ui.getCore().byId("rr_rolename" + "-__" + idRepeater); 
  //alert(control);
  alert(control.getText());
 
     var rows =  rowRepeator.getRows();
     //alert('Index'+ rows);    
      var cellArray = new Array();
   for (var i=0;i<rows.length;i++) { 
    row = rows[i];          
   }
  }
}
);

 

 

Former Member
0 Kudos

Hello Gaurav,

maybe you can get the values without split a string...

try something like this in select :function(oControlEvent)

var table = sap.ui.getCore().getControl(oControlEvent.getSource().getId());

var oModel = table.getModel();

var selectedRowContext = oControlEvent.getParameter("rowContext");

var value = oModel.getProperty("<RowHeader>", selectedRowContext);

greetings

chris

JakobMoellers
Advisor
Advisor
0 Kudos

Hello Chris,

I know this thread is rather old but right now, I am facing the same problem of getting the current row when using the rowrepeater. The solution you posted seems to fit but the problem is that I am told in the console that the object has no method "getSource()". How can that be? Was there a change somewhere so that this is not current anymore?

Thanks!

Former Member
0 Kudos

Dear Jakob,

sorry for that hope, but actually rowRepeater oder viewRepeater have no reserved event for that purpose. You can define your own simple control or try to prototype your template for repeating with clickevent and some hover css styles ? please let me know what you will do.

Regards,

Chris

JakobMoellers
Advisor
Advisor
0 Kudos

Hi Chris,

thanks for your answer! I already started to use normal JavaScript click-events and extract the current row via the id of the div. Now, I try to match this row with the entry in the database (also take the current page into account 😕 )... so I guess this is pretty much the approach that is discussed above...

Regards, Jakob