Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PickList: move all items from target to source issue #2573

Closed
xtoff opened this issue Apr 21, 2017 · 8 comments
Closed

PickList: move all items from target to source issue #2573

xtoff opened this issue Apr 21, 2017 · 8 comments
Assignees
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@xtoff
Copy link

xtoff commented Apr 21, 2017

I'm submitting a ... (check one with "x")

[X] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports)
I had troubles creating a plunkr with primeng version 2.0.5 in combination with picklist from your plunkr, so I hope my explanation is enough :)

Current behavior

I defined two events on my PickList (onMoveToTarget, onMoveToSource). When I log my source and target list in these events everything works fine, except when moving ALL items from target to source. In that case the source and target list is not updated.

Example: I have 3 items in source and 2 in the target list. When I click "move all items to source", the target list still contains 2 items and the source list 3 items.

In all other movements the source/target list are updated during the event.

Expected behavior

When I move all items from target to source, the target list and source list should be updated during the event.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

  • Angular version: 2.4.10
  • PrimeNG version: 2.0.5
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [TypeScript 2.0.10]

  • Node (for AoT issues): node --version = v7.5.0

@bdavidhicks
Copy link

It appears that this.target is spliced before emitting onMoveToSource for moveLeft, but it is spliced after emitting for moveAllLeft. I had to hack a workaround that removed the $event.items manually from my model lists before I did anything else.

moveLeft(sourceListElement) {
        if(this.selectedItemsTarget && this.selectedItemsTarget.length) {
            for(let i = 0; i < this.selectedItemsTarget.length; i++) {
                let selectedItem = this.selectedItemsTarget[i];
                if(this.findIndexInList(selectedItem, this.source) == -1) {
>>>>>>>>>>>>>> this.source.push(this.target.splice(this.findIndexInList(selectedItem, this.target),1)[0]);
                }
            }
            this.onMoveToSource.emit({
                items: this.selectedItemsTarget
            });
            this.selectedItemsTarget = [];
        }
    }

    moveAllLeft() {
        if(this.target) {
            for(let i = 0; i < this.target.length; i++) {
                this.source.push(this.target[i]);
            }
            this.onMoveToSource.emit({
                items: this.target
            });
>>>>>>>>>> this.target.splice(0, this.target.length);
            this.selectedItemsTarget = [];
        }
    }

@xtoff
Copy link
Author

xtoff commented Jun 1, 2017

@bdavidhicks Can you provide an example how you did this with your model lists? Thanks

@xtoff
Copy link
Author

xtoff commented Jun 1, 2017

@cagataycivici Can you take a look at this? I think @bdavidhicks has found the problem in your picklist code.. Thanks

@cagataycivici
Copy link
Member

@Mrtcndkn Take over please.

@cagataycivici
Copy link
Member

Seems by design, onMoveToSource first passes the items that are moved and then updates the list, otherwise you can't know about the items that are moved to source. One idea could be another callback like onMoveAllToSource and onMoveAllToTarget? Thoughts?

@xtoff
Copy link
Author

xtoff commented Jun 1, 2017

That would fix my problem because now it's very hard to check wether I moved one item or all to the source. I need this because I want to check if the target list is going to be empty on a move.

@cagataycivici
Copy link
Member

Thanks, do you expect onMoveToSource to be called in this case, I guess we should not call onMoveToSource and onMoveAllToSource at the same time so that we can separate events.

@xtoff
Copy link
Author

xtoff commented Jun 1, 2017

My opinion is to separate them, but I'm no expert though :)

@Mrtcndkn Mrtcndkn added the Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add label Jun 2, 2017
@Mrtcndkn Mrtcndkn added this to the 4.0.4 milestone Jun 2, 2017
Mrtcndkn added a commit that referenced this issue Jun 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Projects
None yet
Development

No branches or pull requests

4 participants