I encountered this issue, and unfortunately, for responsive web, it’s not possible to natively change the skin of a clicked row in a segment, even though the segment’s skin property has a "pressed" option.
I managed to achieve this with a line of code by creating a dynamic function. This function, when called through the segment’s onRowClick
action, changes the color of the clicked row.
The function dynamically identifies the name of the flex container within the template.
To apply the row skin change, you need to call the function through the segment's onRowClick
action, passing in the parameters: segueWidget
, sectionNumber
, rowNumber
, and segmentId
.
The function uses a global object (selectedRows
) to store the index of the selected row for each segment. The key is created dynamically using the segmentId
(stored as selectedRowKey
), allowing each segment to keep track of its selected row separately. If a row was previously selected (i.e., selectedRows[selectedRowKey]
has a value other than -1), the function resets the skin of the previous row to a default skin (slFbox
), visually deselecting that row.
Note: When calling the function to change the skin, the content of seg.selectedRowItems
is reset.
Before calling the function in the onRowClick
action, define a variable to store the object of the clicked row.
Example:
let segMyListRowItems = self.view.segMyList.selectedRowItems;
After that, call the function.
To retrieve data from the variable, you can do the following:
this.view.txtName.text = segMyListRowItems[0].lblNameUser.text;
rowClickedSeg: function(seguiWidget, sectionNumber, rowNumber, segmentId) {
var flxName = seguiWidget.rowTemplate.split('/').pop();
// Sets the key name for the selected index using the segmentId
var selectedRowKey = “selectedRow_” + segmentId;
// Checks if the previous index is stored and resets it
if (selectedRows[selectedRowKey] !== undefined && selectedRows[selectedRowKey] !== -1) {
var segPrevData = seguiWidget.data[selectedRows[selectedRowKey]];
segPrevData[flxName] = {
“skin”: “slFbox” // Skin Default
};
seguiWidget.setDataAt(segPrevData, selectedRows[selectedRowKey], sectionNumber);
}
// Applies the skin to the selected row
var segData = seguiWidget.data[rowNumber];
segData[flxName] = {
"skin": "sknClickedLine" // Selection skin
};
seguiWidget.setDataAt(segData, rowNumber, sectionNumber);
// Update the selected index for the specific segment
selectedRows[selectedRowKey] = rowNumber;
},
Sorry for any spelling mistakes, I'm Brazilian and I used Google Translate to translate and try to help you.
If you have any questions, I'm at your disposal.