angular / angular/components

[CdkTable] consolidate data index in RowContext

Offen
#14,198 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area: material/table needs: discussion P4
Vorherrschende Sprache
TypeScript
Sterne
25k
Forks
6.8k
Ø Merge
1 T. 8 Std.
Gemergte PRs (30 T.)
91

Beschreibung

#### Bug, feature request, or proposal: proposal

#### What is the expected behavior?
Property pointing at the location of the row in the data source should be the same
for `CdkCellOutletMultiRowContext` and `CdkCellOutletRowContext`

#### What is the current behavior?
The property pointing at the location of the row in the data source is `index` in single-row template mode and `dataIndex` in multi-row tempalte mode.

#### What is the use-case or motivation for changing an existing behavior?

When working with the context, to figure out which property to use one will have to have
access to the table to query `multiTemplateDataRows` or check both properties which is >= 0.

The use case is for more complex tables, where a row model is needed and the context can be used as such.

This get's really annoying when working with templates... you need to explicitly request `index` and `dataIndex` in the template and query for the one in use... because 0 is a valid value doing `||` is not good as you might end up with `undefined`

I know that `RowContext` is public thus `index` and `dataIndex` must stay but it can be deprecated in the long run...

The code in the method `_updateRowIndexContext()` can become:

```ts
context.index = context.dataIndex = this._renderRows[renderIndex].dataIndex;
if (this.multiTemplateDataRows) {
context.renderIndex = renderIndex;
}
```
Instead of

```ts
if (this.multiTemplateDataRows) {
context.dataIndex = this._renderRows[renderIndex].dataIndex;
context.renderIndex = renderIndex;
} else {
context.index = this._renderRows[renderIndex].dataIndex;
}
```

And in future version deprecate one of the properties.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, `_updateRowIndexContext()` und die im Issue vorgeschlagene Änderung zu lesen. Prüfe, wie `index`, `dataIndex` und `renderIndex` für Einzelzeilen- und Mehrzeilen-Template-Modi aktualisiert werden. Erledigt ist die Änderung, wenn beide Zeilenkontexttypen denselben Datenquellenindex bereitstellen, während der Mehrzeilenmodus weiterhin den Renderindex setzt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, typescript
Bereich
frontend
Issue-Typ
Feature
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.