daniel-nagy / md-data-table

Material Design Data Table for Angular Material
MIT License
1.9k stars 519 forks source link

immutable filter selected items #483

Open djleonskennedy opened 8 years ago

djleonskennedy commented 8 years ago

Hello

Have situation where i need to filter items when item removed

function remove(id) {
   vm.items = vm.items.filter(item => item.id === id)
}

but also i have items selected so i should update it as

function remove(id) {
   vm.items = vm.items.filter(item => item.id === id)
   vm.selected = vm.selected.filter(item => item.id === id) // from table model
}

and it works, but one thing isn't i have counter of selected

vm.all = vm.selected.length;

and after filtering of selected items all references are destroyed cause filter return new array (as you know). i can use splice to mutate vm.selected, but i need immutable solution

can we do it in immutable way?

Thank you

djleonskennedy commented 8 years ago

could be fixed in https://github.com/daniel-nagy/md-data-table/pull/403