In this grid, the column (project name) is a button with dynamic button text . i want to change the background color of the complete row when the button present in the row is clicked.
The column project name consists of button with dynamic text.
the project name is a button and i want that when user click on this , the background color of row should change to green.
Hi Abhishek,
Thanks for contacting Syncfusion support.
Based on your requirement, you want to change the background color of the row when the button is clicked. You can achieve your requirement by using the below way.
In the button click event, we dynamically add the custom class to the closest tr element. Using this custom class you can customize the style of the tr element.
columnTemplate: https://ej2.syncfusion.com/react/documentation/grid/columns/column-template/
|
[index.js]
export class Default extends SampleBase { template(props) { var cellValue = props[props.column.field]; // render the button and bind click event return <button onClick={this.btnClick.bind(this)}>{cellValue}</button>; }
btnClick(args) { if (args.target && args.target.closest('tr')) { args.target.closest('tr').classList.add('customrow'); // add a custom class to the closest tr element } } render() { return ( <GridComponent dataSource={orderDetails} height="350"> <ColumnsDirective> <ColumnDirective field="CustomerName" headerText="Customer Name" template={this.template.bind(this)} width="150" ></ColumnDirective> </ColumnsDirective> </GridComponent> </div> </div> ); } }
|
|
[index.html]
<style> // apply css based on custom class .e-grid .customrow, .e-grid .customrow td.e-active { background: green; } </style>
|
Sample: https://stackblitz.com/edit/react-vfxcss?file=index.js
Please get back to us if you need further assistance with this.
Regards,
Rajapandiyan S
https://stackblitz.com/edit/react-vfxcss?file=index.js
can you please Apply this in a function component instead of a class component.
Hi Abhishek,
Thanks for your update.
As per your request, we prepared the same sample with functional component. You can get it from the below link,
Sample: https://stackblitz.com/edit/react-xa25ij-3zxv2j?file=component%2Fapp.jsx
Please get back to us if you need further assistance.
Regards,
Rajapandiyan S
I tried this method, its changing color on click . but sorry , i forgot to mention that i am using template to redirect on button click , so i cannot apply another template in the same column directive.
Hi Abhishek,
Before proceeding with your query, we need few more information on your requirement.
Regards,
Rajapandiyan S
HI Rajapandiyan,
there is a grid on the page when you click on the button present in the grid ,it divides the page into two equal half, one side having the same grid and other side showing the information on the button click. as shown in the images down.
I want a way to highlight the grid row on which the button is clicked , so it can be easily identified that which row data is being watched.
P.S. - For the redirection Part , you can refer to URL shown in the screenshots attached.
after clicking button(project name) , it shows details in the right side. I want to highlight the row which button is clicked and also show the details at the same time.
I know you guys are super busy and very helpful too. But if possible then try to reply fast.
Thank you in advance
Hi Abhishek,
Sorry for the inconvenience caused. We will try to provide the response as fast as we can.
To provide a better solution, we need to understand your issue clearly at our end.
Regards,
Rajapandiyan S
Hello!
thank you for you fast reply,
Hi Abhishek,
Thanks for sharing the details.
By analyzing your query, we suspect that the Grid got refreshed when executing the history.push() method in the button click. We have to prepare the sample with React Router to analyze this behavior at our end. So, we will update the further details on or before May 2nd, 2022.
We appreciate your patience until then.
Regards,
Rajapandiyan S
okay, will be waiting for your response . Reply as soon as possible.
Thanks in Advance.
Hello syncfusion Team, you can close this forum. I was able to achieve the requirement .
thank you for assistance.
Hi Abhishek,
We are glad to hear that you have resolved the reported problem by yourself.
Please get back to us if you need further assistance.
Regards,
Rajapandiyan S