Ag- grid button click doesnt work inside cell
You haven't quite implemented your button correctly. You can't pass a function cellRenderer
, you must pass a component that implements the ICellRendererAngularComp
interface. So you'll need to create your own custom cell renderer for the button.
Something like this:
@Component({
selector: 'app-button-renderer',
template: `
<button type="button" (click)="onClick($event)">{{label}}</button>
`
})
export class ButtonRendererComponent implements ICellRendererAngularComp {
params;
label: string;
agInit(params): void {
this.params = params;
this.label = this.params.label || null;
}
refresh(params?: any): boolean {
return true;
}
onClick($event) {
if (this.params.onClick instanceof Function) {
// put anything into params u want pass into parents component
const params = {
event: $event,
rowData: this.params.node.data
// ...something
}
this.params.onClick(this.params);
}
}
}
And the params you'll need to this component will be your assign
function to tell the button what to call when the button is pressed and the button label:
headerName: "Assign buttons",
width: 100,
cellRenderer: "buttonRenderer",
cellRendererParams: {
onClick: this.assign.bind(this),
label: "Click"
}
Lastly, you'll need to tell the grid about this button by passing in the frameworkComponents
param like so:
frameworkComponents = {
buttonRenderer: ButtonRendererComponent,
}
and in your html:
[frameworkComponents]="frameworkComponents"
Here is a demo.
ag-grid buttonrenderer non-static label for each button
You can just simply use valueGetter
method of the Ag-grid.
We can render the value for the particular column based on it's field value. Please try to change your code something like below,
columnDefs = [
{
headerName: 'Button Col 1',
cellRenderer: 'buttonRenderer',
valueGetter: (params) => this.displayColumnLabel(params.data.fieldName)
cellRendererParams: {
onClick: this.onBtnClick1.bind(this),
label: 'Click 1'
}
},
...
];
displayColumnLabel(fieldValue) {
if(fieldValue) {
return fieldValue; // do something you want to do with value (modifications)
}
return 'some default text or value';
}
Happy Coding.. :)
Ag-grid button in cell that directs to new screen
Create a component and navigate to it with input data.
There are many ways for transforming data between components.
Read this article
In your sample demo you should define route with an id and navigate to it's component then call an api
to fetch the data.
Also you can open a modal to show the data instead.
Example:
CellUpdate(params){
if (params.colDef.field === "changeSettings"){
const modalRef = this.modalService.open(YourEditComponent);
modalRef.componentInstance.data= params;
}
}
Ag-grid how to update cell style by clicking a button
I have'nt tested but I believe its something like this; set buttonClicked
to true on button click.
const gridOptions = {
....
context: {
buttonClicked: false
}
};
In the columnDef:
cellStyle: params => params.context.buttonClicked && params.value > 80 ?
{ border: '1px solid #165a9f' } : { border: 'whatever it is before the button is clicked' }
Related Topics
Javascript Function Not Defined Error (But It Is Defined)
How to Display Loading Message When an Iframe Is Loading
On Click,Redirect to a New Page and Scroll to a Particular Div on That New Page
Center Content Vertically on Vuetify
Observe Localstorage Changes in Js
Regex to Replace Everything Except Numbers and a Decimal Point
Regular Expression for Not Allowing Spaces in the Input Field
Trouble Converting Dates String to Yyyy-Mm-Ddthh:Mm:Ss-Hh:Mm Format
Jquery Ajax Post Results in 500 Internal Server Error
How to Open a File/Browse Dialog Using JavaScript
How to Pass Model Data in JavaScript
How to Delete a Localstorage Item When the Browser Window/Tab Is Closed
How to Disable Clicking Inside Div
How to Trigger Change of Option in Dropdown When Options Can Have Same Value
How to Enable Scrolling on Website That Disabled Scrolling
How to Get Public User All Posts from Instagram, Without Instagram API