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

How to get the row element? #1343

Open
luizhrios opened this issue May 2, 2023 · 1 comment
Open

How to get the row element? #1343

luizhrios opened this issue May 2, 2023 · 1 comment

Comments

@luizhrios
Copy link

Can't find anything on docs or here on the repo about getting the row element. Every event gets the row data but how to get the element?

@luizhrios luizhrios reopened this May 2, 2023
@uap-universe
Copy link

You don't. At least not in a documented way. See also.

In our fork, we added row as an, yet undocumented, property to all DataSourceChange events.

In this original library you need to lookup the data via mytable.grid.getRows().find(r => MyDataClass.equals(r.getData(), event.data)).

Unrelated Off-Topic explanation of the above code

Always be aware of the typical pitfalls in Typescript. You should use an equals method and you should have this method static in your class. Neither == nor === are guaranteed to find the correct element. Another option would be to have an ID attribute and compare r.getData().id === event.data.id but if you ever want to change that in future, you are better off with an equals method.

Now, why should that be static? Because when you start getting your data from a server (like a REST API e.g.) and you are just extracting that JSON, you don't have any methods on that object. Even if you assign a JSON response from a server to a variable of your data class, that class won't have any methods. It even won't have any attributes if some of them are optional in the REST response.

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

No branches or pull requests

2 participants