Programatic row selection seems broken?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.7k
- Forks
- 351
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 1
Description
I have an ember-table where I need to compute the selected row based off of the current route (because the table serves as the master in a master/detail view layout). When rendering a row's detail route, I want that row to be selected. I was doing this in a different part of the app successfully before, but that part of the app has moved away from that layout since, so I'm unsure when it stopped working.
Here's what I'm doing in the component that renders my table to compute the selection as the row which matches the currently rendered detail route (which renders in an {{outlet}} alongside the Orders ember-table:
export default class OrdersTable extends Component {
@service router;
// ...
get selection() {
let { rows } = this;
let { currentRoute, currentRouteName } = this.router;
if (currentRouteName !== 'orders.order') {
return undefined;
}
let orderId = currentRoute.params.orderId;
return rows.find(row => row.id === orderId);
}
// ...
@action
onSelect(selection) {
this.router.transitionTo('orders.order', selection.id);
}
}
In the template, I pass this.selection and this.onSelect to t.body:
<EmberTable as |t|>
<t.head @columns={{this.columns}} />
<t.body
@checkboxSelectionMode="none"
@onSelect={{this.onSelect}}
@rows={{this.rows}}
@rowSelectionMode="single"
@selection={{this.selection}}
/>
</EmberTable>
Though this.selection returns the row object that I would expect, ember-table does not mark the matching table row with the .is-selected class 😬
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the supplied OrdersTable setup with route-derived selection and the shown <t.body> arguments. Trace how @selection is compared with @rows and how the .is-selected class is applied; done means the row matching the current order route receives that class.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100