|
[b]Update:[/b] the declared type of [c]rowCustomSelect[/c] now matches the real call order, [c]($event, rowData, dt)[/c]. Fixed in [url=https://wuic-framework.com/downloads/release-notes#v1.8.0]WUIC Framework 1.8.0[/url].
[i]The original answer below describes versions before 1.8.0.[/i]
[b]Update (4 November 2026):[/b] the documentation has been fixed. The [url=https://wuic-framework.com/docs/list-grid]List Grid[/url] and Data Repeater pages now show the signature the framework actually uses, [c]($event, rowData, dt)[/c], and from the next release after 1.7.31 the TypeScript declaration of the input matches it too. The answer below is still valid: runtime behaviour has not changed.
[b]Question[/b]
I bound a handler to the [c]rowCustomSelect[/c] input of [c]<wuic-list-grid>[/c] to open a dialog when the user clicks a row. The handler is typed as [c](rowData, $event, dt)[/c], like the declaration of the input, but my guard on [c]rowData?.id[/c] always returns early and nothing happens. No console error. What is going on?
[b]Answer[/b]
At runtime the grid calls the callback with the arguments in a different order than the declared type: the call is [c]rowCustomSelect($event, rowData, dt)[/c], so the event comes first and the record second. The input is declared as [c](rowData: any, $event: any, dt: Table) => void[/c], and the compiler does not complain because every parameter is [c]any[/c]. Your handler receives the DOM event in the [c]rowData[/c] slot, [c]rowData?.id[/c] is [c]undefined[/c], the guard returns, and the failure is completely silent.
The fix is to follow the real order:
[code]
// host component
onRowSelected = (_event: any, rowData: any, _dt: any): void => {
if (!rowData?.id) return;
this.openDetail(rowData);
};
[/code]
[code]
<wuic-data-source #ds [hardcodedRoute]="'preventivi'" [autoload]="true"></wuic-data-source>
<wuic-list-grid [hardcodedDatasource]="ds" [rowCustomSelect]="onRowSelected"></wuic-list-grid>
[/code]
Two more details worth knowing:
[list]
[*]Define the handler as an arrow-function property, as above. The grid invokes it as a method of its internal row template, so a regular method would lose the [c]this[/c] of your host component.
[*]When [c]rowCustomSelect[/c] is set, the grid switches the table to single selection and stores the clicked record as the current selection, so the selected row is highlighted without extra code.
[/list]
If you are debugging a handler that does nothing, log [c]arguments[/c] first: you will see the event object where you expected the record.
[url=https://wuic-framework.com/docs/list-grid]Documentation: List Grid[/url]
|