angular / angular/components

Relax MatTableDataSource’s filter to be of type “{}”

Aperta
#16,112 8 commenti 6 reazioni 0 assegnatari Vedi su GitHub
area: material/table feature P3
Lingua principale
TypeScript
Stelle
25k
Fork
6.8k
Merge medio
1g 8h
PR unite (30g)
91

Descrizione

#### Feature Description
Relax `MatTableDataSource.filter` to accept `{}`. Right now, it is restricted to `string`.
This would allow *much* easier custom filtering on multiple dimensions.

#### Use Case
When the filter is “only” a string, it makes it very difficult to “structurally” filter a table on multiple dimensions, even when customizing `filterPredicate` . Some recommendations on internet include:
- passing a JSon object, and parsing the JSon `filterPredicate`, for each and every row: http://nataliesmith.ca/blog/angular-material-filter-table
- everything in this bug thread: https://github.com/angular/components/issues/6178

While it works, it’s also a gratuitous workaround: It turns out that at no point does `MatTableDataSource` actually *require* filter to be a `string`: Whatever gets passed to `filter` just gets piped “as-is” to `filterPredicate`.

Here is a simple fork of “Table with filtering” that filters on different columns individually, where all I did was pass my complex object, while not respecting :
https://stackblitz.com/edit/table-filtering-multiple-filters-example?file=app/table-filtering-example.html
https://table-filtering-multiple-filters-example.stackblitz.io/

#### Caveats

It would still be up to the caller to make sure that their `filter` object is homogeneous with their `filterPredicate` object.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia dal punto di ingresso MatTableDataSource.filter e analizza come il suo valore viene passato a filterPredicate. Aggiorna il tipo pubblico in modo che accetti {}, preservando il flusso esistente del predicato, quindi verifica che gli oggetti filtro strutturati multidimensionali funzionino senza richiedere una conversione JSON.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
angular, typescript
Ambito
frontend
Tipo di issue
Funzionalità
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.