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

[Documentation] Document ability to bind to v-data-table row clicks and use column value callbacks #20243

Open
merlinz01 opened this issue Jul 30, 2024 · 4 comments

Comments

@merlinz01
Copy link

Problem to solve

I just discovered this solution for making v-data-table rows clickable. I wish this had been documented, as it would have saved me some time, and would help new users wanting to implement CRUD operations or navigating in response to clicks.

Proposed solution

Document the relevant API with examples.

@merlinz01
Copy link
Author

First, is there a solution for this?

@merlinz01
Copy link
Author

merlinz01 commented Jul 30, 2024

What if we would change


to something along the lines of

  // (type hints removed)
  onClick={ props.onClick ? (event) => props.onClick(event, props.item) : undefined }

so that one can access the row data like this:

function rowClickCallback(event: MouseEvent, item: MyItemType) {
    console.log(`Item ${item.name} was clicked.`)
}
<v-data-table @click:row="rowClickCallback" :items="myItems" />

That way we wouldn't have to depend on a hack to determine which row was clicked. I don't think such a change would affect existing code.

Unless there is a simpler solution that I'm missing.

@KaelWD
Copy link
Member

KaelWD commented Jul 30, 2024

This is already the case, did you try it?

getPrefixedEventHandlers(attrs, ':row', () => slotProps),

We need to figure out how to document these events, the keys are dynamic so can't just be added to the component definition.

@merlinz01
Copy link
Author

Can't say I understand what that line does, but I'm glad it works. Thanks for pointing out a solution.

It would be great to document the events also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants