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

Programmatic element (pre-)selection on datatable fails when using dataKey #3618

Closed
gdj1975 opened this issue Aug 9, 2017 · 2 comments
Closed
Assignees
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@gdj1975
Copy link

gdj1975 commented Aug 9, 2017

I'm submitting

[ 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)
Please fork the plunkr below and create a case demonstrating your bug report. Issues without a plunkr have much less possibility to be reviewed.

http://plnkr.co/edit/UZiAHEmvc3IldUTHTNyH?p=preview

Current behavior
Setting a selected item on a datatable that uses a dataKey does not work in single selction mode. The selection object and the selection keys are not correctly initialized, when selection is a single object instead of an array.

Expected behavior
Setting the selected item as object in single selection mode should use the datakey property to check equality.

Minimal reproduction of the problem with instructions
http://plnkr.co/edit/UZiAHEmvc3IldUTHTNyH?p=preview

** Issue and Fix

if(this._selection) {
for(let data of this._selection) {
this.selectionKeys[String(this.objectUtils.resolveFieldData(data, this.dataKey))] = 1;
}
}

        if(this._selection) {
            if (Array.isArray(this._selection)) {
                for(let data of this._selection) {
                    this.selectionKeys[String(this.objectUtils.resolveFieldData(data, this.dataKey))] = 1;
                }
            }
            else {
                this.selectionKeys[String(this.objectUtils.resolveFieldData(this._selection, this.dataKey))] = 1;
            }
        }
  • PrimeNG version: 4.1.2
@gdj1975 gdj1975 changed the title Preselection with programatic element (pre-)selection on datatable fails when using dataKey Aug 9, 2017
@hugograf
Copy link
Contributor

hugograf commented Sep 6, 2017

I can confirm this error. The fix of "gdj1975" would fix this problem!

hkjeffchan added a commit to hkjeffchan/primeng that referenced this issue Oct 12, 2017
@cagataycivici cagataycivici self-assigned this Oct 19, 2017
@cagataycivici cagataycivici added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working Status: Pending Review Issue or pull request is being reviewed by Core Team labels Oct 19, 2017
@cagataycivici cagataycivici added this to the 4.2.3 milestone Oct 19, 2017
@cagataycivici
Copy link
Member

Got it, thanks.

hkjeffchan added a commit to hkjeffchan/primeng that referenced this issue Dec 18, 2017
This reverts commit 3ed26f7.
@cagataycivici cagataycivici changed the title programatic element (pre-)selection on datatable fails when using dataKey Programmatic element (pre-)selection on datatable fails when using dataKey May 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

3 participants