shlomiassaf / ngrid

A angular grid for the enterprise
https://shlomiassaf.github.io/ngrid
MIT License
240 stars 39 forks source link

[Feature] "selected" CSS class on the row based on selection in PblDataSource.selection #202

Open spali opened 3 years ago

spali commented 3 years ago

Please describe the feature you would like to request.

would like to have "selected" CSS class on the row based on selection in PblDataSource.selection.

What is the use-case or motivation for this proposal?

I try to build a reusable table component based on ngrid for an application. For that, I created a plugin directive which does support selection based on rowClick from the targetEvents plugin. It also has a feature to use shift select to select multiple rows. Because I don't want to have the additional select checkbox, I want to highlight the rows by inverting the row colors. I got it managed by setting the rowClassUpdate to return a custom class for selected rows and temporary set rowClassUpdateFreq = 'ngDoCheck' and force a detectChanges(). and then set the rowClassUpdateFreq back to the origin value. But the rowClassUpdate feature feels more like for the user to be used for custom stuff and I would like to have a solution without setting this function and to occupy it for the user. Also I don't want to mess with the focus feature, because I want the user of the component to decide if he want's to use this feature and how.

I see two possible solutions:

laryk9 commented 3 years ago

Hey, @spali I agree with you and I also think this feature is necessary. In the meantime, I suggest you use the custom row feature (see reference: custom row). With custom row, you can just define a simple ng-class instead of toggling the rowClassUpdate and running the change detector.

spali commented 3 years ago

Hi @laryk9 Thanks for your response. Yes, I started with the custom row feature. But since the select functionality is in a directive plugin I don't have access to a template from there. Sure it would be possible to do it in the reusable component that I build on top of that directive. So I have even two possible workarounds till the feature will come ;) But at the end of the day which workaround doesn't make a difference for me, because I'm currently also in control of the component, so anyway the user does not have access to the rowClassUpdate when not using the directive directly. And I assume the performance is almost the same.