Skip to Content
0
Aug 13, 2012 at 07:19 PM

RowRepeator event for reading current Row

40 Views

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);