Hi there
I am creating a datagrid using grid component. I used detail template to show more information when the user click on the collapse/expand arrow.
Just want to check is there any way to apply css to rows that are currently expanded? i have create a sample image below:
Thank you
Regards
Yu Feng
|
Index.js
detailDataBound(args) {
args.detailElement.parentElement.previousSibling.classList.add(
'c-expanded'
); // this event will be triggered only the first time when you expand the rows
}
onLoad() {
this.gridInstance.on('detail-state-change', args => {
if (args.isExpanded) { // this event will be triggered everytime when you expand and collapse //except the first time
args.detailElement.parentElement.classList.add('c-expanded');
} else {
args.detailElement.parentElement.classList.remove('c-expanded');
}
});
}
render() {
return (
<div className="control-pane">
<div className="control-section">
<GridComponent
enableHover={false}
ref={grid => (this.gridInstance = grid)}
dataSource={employeeData}
created={this.onLoad.bind(this)}
detailDataBound={this.detailDataBound.bind(this)}
detailTemplate={this.template.bind(this)}
width="auto"
>
<ColumnsDirective>
<ColumnDirective
field="FirstName"
headerText="First Name"
width="110"
/>
<ColumnDirective
field="LastName"
headerText="Last Name"
width="110"
/>
<ColumnDirective field="Title" headerText="Name" width="150" />
<ColumnDirective
field="Country"
headerText="Country"
width="110"
/>
</ColumnsDirective>
<Inject services={[DetailRow]} />
</GridComponent>
</div>
</div>
);
}
} |
|
Index.css
.e-grid .c-expanded td {
background-color: aqua;
}
.c-rowcell {
background-color: rgb(91, 247, 156);
} |
Hi Ajith
The solution is working great! thank you for your assistance
Regards
Y
Hello,
I also have the exact requirement; I achieved this using the provided example. Thanks for your response and detailed explanation!
There is only one issue left on my side. I'm using typescript and looking for a way to provide typing support on the classList property.
The error is: Property 'classList' does not exist on type 'ChildNode'.
And I'm also looking for the argument type of the second parameter of gridRef.current.on method which is args:any at the moment.
Hi Can,
Greetings from Syncfusion support.
Based on your query, you want to add the type of the args of the `detail-state-change` event and also add type to the `args?.detailElement?.parentElement?.previousSibling?.classList`. Please refer the below code example for more details.
|
const detailDataBound = (args: DetailDataBoundEventArgs) => { ( args?.detailElement?.parentElement?.previousSibling as Element )?.classList.add('c-expanded'); };
const onLoad = () => { if (gridRef && gridRef.current) gridRef.current.on( 'detail-state-change', (args: { data: object; childGrid: GridModel; detailElement: Element; isExpanded: Boolean; }) => { if (args.isExpanded) { args.detailElement.parentElement.classList.add('c-expanded'); } else { args.detailElement.parentElement.classList.remove('c-expanded'); } } ); };
|
Regards,
Joseph I.