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

DataTable: support passing a function to the dataKey prop #2589

Closed
nestorrente opened this issue May 31, 2022 · 0 comments
Closed

DataTable: support passing a function to the dataKey prop #2589

nestorrente opened this issue May 31, 2022 · 0 comments
Assignees
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@nestorrente
Copy link
Contributor

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

[x] bug report
[x] feature request
[ ] support request

This can be considered a bug report or a feature request, depending on the point of view.

CodeSandbox Case (Bug Reports)

https://codesandbox.io/s/purple-cloud-j8ehhg?file=/src/App.vue

Current behavior
The DataTable works as expected, but a warning is shown in the console:

[Vue warn]: Invalid prop: type check failed for prop "dataKey". Expected String with value "function () { [native code] }", got Function

Expected behavior

No warning.

Minimal reproduction of the problem with instructions

Instead of passing a String in the dataKey property, use a Function.

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

Sometimes a simple property is not enough for specifying the unique key of the items. For example, if you have a database table that uses a Composite PK, you will need to use 2 or more columns in order to get a unique identifier for each object.

If the dataKey property of the DataTable supports passing a function, the developer of the application will be able to indicate how that unique key must be generated, no matter how complex that logic is.

This is actually already supported, as the dataKey prop is evaluated using the ObjectUtils.resolveFieldData(data, field) method, which supports passing a function in the field parameter. However, as the prop is declared as String, Vue shows an annoying warning each time the component is rendered.

Please tell us about your environment:

  • Vue version: 3.2.33
  • PrimeVue version: 3.12.6
  • Browser: all
@cagataycivici cagataycivici added the Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add label May 31, 2022
@cagataycivici cagataycivici added this to the 3.13.0 milestone May 31, 2022
tugcekucukoglu added a commit that referenced this issue May 31, 2022
Fixed #2589 - DataTable: support passing a function to the dataKey prop
tugcekucukoglu added a commit that referenced this issue Sep 7, 2023
Fix #2589 vue.js warning for DataTable with dataKey as a function
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

3 participants