sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

ListViewCommand: event.selectedRows not updating

Open jordyvanbremen opened this issue 7 years ago • 39 comments

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. image

my versions: image

jordyvanbremen avatar Oct 16 '19 10:10 jordyvanbremen

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

msft-github-bot avatar Oct 16 '19 10:10 msft-github-bot

Same problem here. Tenant is set to targeted release.

cwdata avatar Oct 16 '19 13:10 cwdata

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

jimmywim avatar Oct 17 '19 09:10 jimmywim

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.

richardpoyner avatar Oct 17 '19 13:10 richardpoyner

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.

cwdata avatar Oct 18 '19 13:10 cwdata

I am also seeing the same issue. Tenant in targeted release.

patrikhellgren avatar Oct 20 '19 00:10 patrikhellgren

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 : image

If i click here, it works image

BraunJonathan avatar Oct 24 '19 09:10 BraunJonathan

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.

ltdu avatar Oct 24 '19 21:10 ltdu

Thanks for the heads up. I reached out to the team, and they found the issue. They are working on a fix.

patmill avatar Oct 24 '19 22:10 patmill

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 avatar Nov 04 '19 10:11 jhamoud

@jhamoud Looks like events work correct if command is registered for both ContextMenu and CommandBar:

<CustomAction Location="ClientSideExtension.ListViewCommandSet"/>

23W avatar Nov 05 '19 17:11 23W

@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.

yeahgoodthanks avatar Nov 06 '19 05:11 yeahgoodthanks

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;
}

23W avatar Nov 06 '19 11:11 23W

@patmill Do you have some info when this bug will be fixed?

23W avatar Nov 06 '19 14:11 23W

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.

hamedy avatar Nov 07 '19 11:11 hamedy

We are having the same issue. Is there an estimated timeline on the fix?

matthong avatar Nov 07 '19 16:11 matthong

Can we use JSOM to detect real selection in the list? E.g. SP.ListOperation.Selection.getSelectedItems()

23W avatar Nov 10 '19 00:11 23W

Sort of workaround: To bypass this issue in a good manner we have created a field customizer containing our own dropdownmenu: image

And then you can get the id using image

zaiby avatar Nov 11 '19 09:11 zaiby

@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.

23W avatar Nov 11 '19 11:11 23W

Sort of workaround: To bypass this issue in a good manner we have created a field customizer containing our own dropdownmenu: image

And then you can get the id using image

nice try but you're gonna need to deal with another bug there. https://github.com/SharePoint/sp-dev-docs/issues/4656

hamedy avatar Nov 11 '19 11:11 hamedy