ListViewCommand: event.selectedRows not updating
Category
- [ ] Question
- [ ] Typo
- [x] Bug
- [ ] Additional article idea
Expected or Desired Behavior
Our ListViewCommand buttons are not working anymore. When selecting a specific item in a list and clicking our command button, at first there is no issue. When selecting another item in the list and then clicking the command button, event.selectedRows is still referring to the item that was selected initially. Only when I deselect an item before selecting another item, the selectedRows is showing the actual selected item. If I jump from Item 1 to Item 2 (without deselecting Item 1), selectedRows is not updated accordingly.
Observed Behavior
When selecting an item in the list, event.selectedRows should be updated accordingly.
Steps to Reproduce
- Create a new ListView command extension
- run gulp serve
- select an item in the list (i.e. Item 1)
- select another item in the list (i.e. Item 2)
- check event.selectedRows (it refers to Item 1)
See also this video repro: https://1drv.ms/v/s!AqmJ4PFCanuAnehX6Szz_7IS4Up1KQ
I'm logging the selected item ID from the onExecute method.

my versions:

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
Same problem here. Tenant is set to targeted release.
I didn't see this issue yesterday, but I raised the same problem just a couple of hours after this. Identical reproduction scenario
https://github.com/SharePoint/sp-dev-docs/issues/4772
Having the same issue here. OnExecute triggers only when the number of selected items has changed. So 1 item and selecting 2 will trigger. But selecting 1 item and then directly selecting another then there is no trigger.
Adding @patmill and @VesaJuvonen for increased visibility as this is a severe problem. Commands silently operating on the wrong list item shouldn't be an issue for too long.
I am also seeing the same issue. Tenant in targeted release.
Same here but only when clicking on the line itself... When clicking on the chckmark, everything works fine... Tenant in standard release...
If i click here in the line, it does not work :

If i click here, it works

We are having the same issue - contents of event.selectedRows changes only if amount of selected rows in view changes.
Additionally tested with simple solution based on 1.9.1 and could reproduce this issue on both SR and TR rings.
Thanks for the heads up. I reached out to the team, and they found the issue. They are working on a fix.
Do we have an estimated timeline on the fix. I'm surprised a bug with this level of severity hasnt been addressed yet. We have users thinking they're executing a command on one item where in fact SharePoint is executing the command on a completely different item. It's basically wrecked havoc on our environment and there's now way to prevent it from happening.
@jhamoud Looks like events work correct if command is registered for both ContextMenu and CommandBar:
<CustomAction Location="ClientSideExtension.ListViewCommandSet"/>
@23W
@jhamoud Looks like events work correct if command is registered for both ContextMenu and CommandBar:
<CustomAction Location="ClientSideExtension.ListViewCommandSet"/>
That's not the case in my environment at least - I already had it set up for both and I've had this same issue. I just double checked and it hasn't come good yet.
Maybe there is other way how to detect right selection in list view, e.g. via DOM ? How about such code?
import * as $ from 'jquery';
// optional filtering item by name
function filterItem(itemName: string) : boolean {
return true;
}
// find the first selected item name in list view (in both view mode: records table and tiles)
export function getSelectedItemName(): string {
let selectedItemName: string = '';
const selectedRows = $("[role='grid'] .is-selected[role='row']:first");
if (selectedRows.length > 0) {
selectedRows.find('button.ms-Link')
.each(function () {
if (filterItem(this.innerText)) {
selectedItemName = this.innerText;
return false;
}
});
}
else {
const selectedTiles = $("[role='list'] .ms-Tile--isSelected:first");
if (selectedTiles.length > 0) {
selectedTiles.find('.ms-Tile-nameplate [data-automationid="name"]')
.each(function () {
if (filterItem(this.innerText)) {
selectedItemName = this.innerText;
return false;
}
});
}
}
return selectedItemName;
}
@patmill Do you have some info when this bug will be fixed?
Maybe there is other way how to detect right selection in list view, e.g. via DOM ? How about such code?
import * as $ from 'jquery'; // optional filtering item by name function filterItem(itemName: string) : boolean { return true; } // find the first selected item name in list view (in both view mode: records table and tiles) export function getSelectedItemName(): string { let selectedItemName: string = ''; const selectedRows = $("[role='grid'] .is-selected[role='row']:first"); if (selectedRows.length > 0) { selectedRows.find('button.ms-Link') .each(function () { if (filterItem(this.innerText)) { selectedItemName = this.innerText; return false; } }); } else { const selectedTiles = $("[role='list'] .ms-Tile--isSelected:first"); if (selectedTiles.length > 0) { selectedTiles.find('.ms-Tile-nameplate [data-automationid="name"]') .each(function () { if (filterItem(this.innerText)) { selectedItemName = this.innerText; return false; } }); } } return selectedItemName; }
done such things in the past and it was never a good idea. DOM might change and we have no control over that. For now I'm going to prompt the user with the selected file info when they trigger the extension and ask them to use radio buttons if selected item is wrong. Hoping that a fix will be rolled out soon.
We are having the same issue. Is there an estimated timeline on the fix?
Can we use JSOM to detect real selection in the list?
E.g. SP.ListOperation.Selection.getSelectedItems()
Sort of workaround:
To bypass this issue in a good manner we have created a field customizer containing our own dropdownmenu:

And then you can get the id using

@zaiby Could you please provide bit more information. Why dropdown menu? How can field customizer can help list view commands set, it's different extensions? By the way, looks like field customizer doesn't work in Tiled View mode, so u can't collect items ids in this mode view field customizer.
Sort of workaround: To bypass this issue in a good manner we have created a field customizer containing our own dropdownmenu:
And then you can get the id using
nice try but you're gonna need to deal with another bug there. https://github.com/SharePoint/sp-dev-docs/issues/4656