QuestionI add a per-row button to a
<wuic-list-grid> from my component: in
ngOnInit I push a column with
mc_ui_column_type: 'button' into
columnMetadata and put my code, as a string, in the callback field. The button is rendered but it is greyed out and clicking does nothing. The same string works when the column is defined in the database. What is different?
AnswerIn code you must set the
function mc_button_action__fn, not the callback string.
The string (
mc_button_action) is compiled into
mc_button_action__fn by the metadata provider only while the metadata is being loaded from the server. A column you push afterwards, from a
fetchInfo$ subscription, is never compiled. The row button checks
mc_button_action__fn to decide whether it is enabled, so without it the button stays disabled.
The callback receives
(datasource, record, event, field, wtoolbox). Note that
record is a map of
BehaviorSubject, so read values with
.value. Also set
mc_button_caption, otherwise the label falls back to the column name.
ngOnInit() {
this.ds.fetchInfo$.subscribe(info => {
if (!info?.metaInfo) return;
const cols = info.metaInfo.columnMetadata;
// fetchInfo$ is a BehaviorSubject and re-emits: keep it idempotent
if (cols.some(c => c.mc_nome_colonna === 'rinnova_action')) return;
cols.push({
mc_nome_colonna: 'rinnova_action',
mc_ui_column_type: 'button',
mc_button_caption: 'Rinnova',
mc_button_image: 'pi pi-refresh',
mc_button_action__fn: (datasource: any, record: any, event: any, field: any, wtoolbox: any) => {
const id = record['CustomerTransactionID']?.value;
// ... call your endpoint with id ...
datasource.fetchData(); // refresh the grid (not refresh())
},
} as any);
});
}
Mistake to avoidDo not mix the two paths: database metadata = callback string, in-code = function. Also remember that the toolbar (table) actions live in a different array, so a row button never goes there.
Documentation: Custom Actions