-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
map instead of set in selection #12363
Comments
@urbanogb it's not clear what you're referring to. Can you elaborate with links to specific code and examples? |
Ok |
@jelbourn, a sample of propose for change in cdk selection is in |
@urbanogb I'm still not clear which code in Angular Material you're referring to. |
The source is: At the line #16, i propose change private _selection = new Set(); by private _selection = new Map<string , T>(); In the constructor add a new parameter: keyField this parameter is the name of the property of that is its unique key. constructor( When data is obtained through a remote connection with a database, it is usually necessary to identify each row in order to later make changes to it. In summary, the problem that I want to solve with the proposal is that the data selected by the user is "lost" when the tables are fed by a request by http, since each time the data is received a new array is created and the _selection property of type Set point to an array that no longer exists. I came across this problem and I deduced that the cause was the Set collection. To prove it in my example, in import {SelectionModel} from './selection'; by import {SelectionModel} from '@ angular / cdk / collections'; Once this is done, if rows are selected on page 1 and advanced to 2 when they return to 1, they are no longer selected. Thank you very much for your patience, it is clear that I am not good at explaining things. |
I don't see how changing to a map would prevent entries from being orphaned. The user would still need to either clear the selection or mark specific items as not-selected in order to remove them from memory. |
I created the example with the material template: table, instead of importing the SelectionModel class from cdk / collectios, I have put an outline of the one I propose. you can try the example with my proposal and With the import of cdk / collections. The example is not complete. the problem is not to delete the selection, since Map, like Set, has a clear method that allows you to erase everything. I have seen that unchecking everything in the original class goes from item to item, this is ineffective. Clear is adequate. The problem is to select everything, in remote tables it is easy to have thousands or millions of records. So remove the option to select / deselect everything, but I can make a proposal of that. The idea is to add a property _containsSelected: boolean = true; This property indicates whether the data in the _selected array is the selected or unselected items Inverting the selection would only change that flag. A user would never mark many items with his mouse. I must do this for a real case in my company, if you want, in a few days I send you the version of that class much more mature ir a New SelectionModelMap. |
@jelbourn , I have created a new branch in the sample-sel App with the proposal Solution. The brach name is markation In this sample, selected row and marked row are diferent concepts. Selected rows = marked rows Or Selected rows = All rows - marked rows, With this sample The user selection persist on change page, Order, filter etc. With material/Cdk/collections/selection.ts the user selection Is cleared on change page etc.. |
@jelbourn , Try this in console: In the table the rows are Objects, no primitive values Set(Value) is the same of Map(Value,Value). Set is a Map with key=value If a value is a primitive value (integer,string, etc.) key is the value, in other case key is a REFERENCE OF value. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
Proposal
What is the expected behavior?
In tables with pagination that is obtained by rest on databases, row objects are recharged and therefore elements in the set collection of the selection class remain orphaned, with map, since the rows have an id this would not happen.
What is the current behavior?
What are the steps to reproduce?
Providing a StackBlitz reproduction is the best way to share your issue.
StackBlitz starter: https://goo.gl/wwnhMV
What is the use-case or motivation for changing an existing behavior?
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Is there anything else we should know?
The text was updated successfully, but these errors were encountered: