How to add inline button for each grid rows when click on it , update some field in dialog #5411
-
Beta Was this translation helpful? Give feedback.
Answered by
minhhungit
Jan 29, 2021
Replies: 1 comment 3 replies
-
You added button, now you need to write code for onClick event Here I update 2 fields Full & Short of State table using StateService @Serenity.Decorators.registerClass()
export class StateGrid extends Serenity.EntityGrid<StateRow, any> {
protected getColumnsKey() { return 'Default.State'; }
protected getDialogType() { return StateDialog; }
protected getIdProperty() { return StateRow.idProperty; }
protected getLocalTextPrefix() { return StateRow.localTextPrefix; }
protected getService() { return StateService.baseUrl; }
protected getInsertPermission() { return StateRow.insertPermission; }
constructor(container: JQuery) {
super(container);
}
protected getColumns() {
var columns = super.getColumns();
columns.unshift({
field: 'Update Button',
name: '',
format: ctx => '<a class="inline-action update-full-and-short" title="delete">' +
'<i class="fa fa-edit text-green"></i></a>',
width: 24,
minWidth: 24,
maxWidth: 24
});
return columns;
}
counter: number = 0; // demo change
protected onClick(e: JQueryEventObject, row: number, cell: number) {
super.onClick(e, row, cell);
if (e.isDefaultPrevented())
return;
var item = this.itemAt(row);
var target = $(e.target);
// if user clicks "i" element, e.g. icon
if (target.parent().hasClass('inline-action'))
target = target.parent();
if (target.hasClass('inline-action')) {
e.preventDefault();
if (target.hasClass('update-full-and-short')) {
this.counter++;
StateService.Update({
EntityId: item.Id,
Entity: {
Full: item.Full + "_" + this.counter,
Short: item.Short + "_" + Math.random()
}
}, res => {
Q.notifySuccess("Updated");
this.refresh();
})
}
}
}
} |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
waleed51
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You added button, now you need to write code for onClick event
Here I update 2 fields Full & Short of State table using StateService