0 votes
4.1k views
in Coach Views by (120 points)
I'm using IBM BAW OOTB SparkUI Table. I created list of objects and mapped to table. With Single Select configuration i tried to get the row index but i'm getting message as "Selected row has index undefined". I tried all possible solutions across search but I couldn't fix it. I tried Event section to get the row index. Any code sample would be highly appreciated.

Verified all solutions

https://www.ibm.com/docs/en/baw/19.x?topic=toolkit-table

1 Answer

0 votes
by (30.6k points)

"Selected row has index -1" means the table has no selected record at the moment you ask. Two reasons are common: reading in the wrong event, or reading through the wrong API. The UI Toolkit table gives you the record directly:

// Table control (UI Toolkit), single select
// 1. In the table's "On row selected" event (fires with the selected record):
//    event signature: (row, record, index)  ->  record is the bound list element
${Details}.setData(record);                  // e.g. show it in a Data / form section
console.log("selected index", index, "id", record.id);

// 2. From a button handler afterwards:
var t = ${Orders};                           // control id of the table
var rec = t.getSelectedRecord ? t.getSelectedRecord() : t.getSelectedRecords()[0];
var idx = t.getSelectedIndex ? t.getSelectedIndex() : t.getSelectedIndices()[0];
if (idx < 0) { alert("Select a row first"); return; }
var byIndex = t.getRecord(idx);              // the record for any index
// the bound list itself: ${Orders}.getData() or the coach variable
var list = ${Orders}.getData(); var same = list[idx];

Why -1 happens: the table is bound to a list that is re-set (for example a service result assigns a new list) - every new list clears the selection; a click inside a cell control (button, checkbox) does not select the row on older toolkits unless Select on click is on; on the Multi selection mode there is no single index, use getSelectedIndices().

Also note the table shows the filtered / sorted order: getSelectedIndex() is the index in the displayed table, getSelectedRecord() is always the real record - prefer the record over the index and look it up by an id field in the bound list.

References

Related questions

+1 vote
1 answer 1.2k views
0 votes
1 answer 1.4k views
0 votes
1 answer 2.3k views
0 votes
1 answer 2.2k views
0 votes
1 answer 4.0k views
0 votes
1 answer 1.1k views
0 votes
1 answer 872 views
0 votes
4 answers 4.5k views
0 votes
1 answer 1.6k views
0 votes
1 answer 1.7k views

723 questions

807 answers

98 comments

4.9k users

Join BPM Community Discord Channel

Welcome to BPM Tips Q&A, Community wiki/forum where you can ask questions and receive answers from other IBM BPM experts and members of the community. Users with 2000 points will automatically be promoted to expert level.
Created by Dosvak LLC
Our Youtube Channel
...