Unable to dynamically select a table row using selectRow

I'm using the "Table(new)" component to render a list of items, and would like to select all of the items in the list by default whenever a new query for data is complete.
Unfortunately I'm having trouble getting this to work by using the selectRow API as suggested in other threads such as this one and this one.

I've tried this both for tables in single-select and multi-select mode, and I can't get selectRow to do anything.


However, both the above cases seem to work fine if I use the Table(legacy) component instead. Is there a work-around that allows us to use the new table like this, or should we switch to legacy?

Definitely sounds like a feature that hasn't been implemented yet in the new table.


However if you look at .selectRow on new table it will return first matching value.

Additionally it seems like .selectRow in the new table only accepts a value and not array thus making this impossible perhaps?
image

Tagging @Alexi for visibility!

Thanks @jcd and @stefancvrkotic for writing in! selectRow doesn't currently support selecting multiple rows, but I've noted it as a feature request.

For the single select case, the selectRow API, takes in an object with mode which can be 'key' or 'index'. Use key for targeting a row by its primary key, otherwise use index to target an index by display, or data.

Some examples:

// Selects row with primary key 4
table1.selectRow({ mode: 'key', key: 4 })

// Selects the row that represents table1.data[4]
table1.selectRow({mode: 'index', indexType: 'data', index: 4})

// Selects 5th row visible on the table
table1.selectRow({mode: 'index', indexType: 'display', index: 4})

Hope this helps! We will make a note of the feedback to add more documentation to help guide the usage of the selectRow API.

1 Like

Thank you @AnnaW for the response!
Good to see that this is supported for single selections.
Support for selecting multiple rows is required for my use case but we can probably find a workaround for the near-term. :slight_smile:

Hey @jcd!

Just want to mention here that selecting multiple rows is now supported :tada:

If row selection for the table is set to "Multiple" you should now be able to pass an array of indices to the selectRow function, e.g.:

table1.selectRow({ mode: 'index', indexType: 'display', index: [0, 1] })
1 Like

Are there plans to support "keys" so I can pass in keys instead of indices? It's so much easier to pass a selection of keys rather than indices.

Also - is there a way to preserve the selection so when I use "selectRow", I'm not clearing the selection?

1 Like

Hey @pockeet! Keys should be supported for multi-select as well, it looks like there's a bug here. We can report back when it's fixed!

Hey @Kabirdas, any update here?

Would like to pass in an array of values defined by a multilistbox selection to a table selection.

Hoping I could pass this array to select matching rows.

Not sure if this issue is still relevant, but it seems to be possible to pass an array of values to the selectRow function.

I used this JS to compare two tables, and select the lines appearing in both tables.

const arrXLS = table2.data.map(row => row.oid)
const arrSQL = table3.data.map(row => row.oid)

const arrBoth = arrXLS.filter(element => arrSQL.includes(element));

table2.selectRow( {mode: 'key', key: arrBoth })

Thanks for replying here @Ronaldvm! It looks like this has been fixed by some separate work done by the dev team. Bumping this for you @nels5722 in case you haven't already seen this and still need it.