Hi, I am using React Syncfusion Grid's custom template for customizing my column.
My Question is How can I use my own components and functions to customize the column?
default
column=[{template:`<button>${value}</button>`,width:3000}]
I want to use
column=[{ template:`<myComponentButton>${myfunction(value)}</myComponentButton>` }]
I was also not able to pass a function to template -{template:templateFunc} to achieve the above functionality .
Any help is appreciated
Thankyou
|
[index.js]
export class Default extends SampleBase {
constructor(props) {
super(props);
}
template(args) {
console.log(args);
// return your custom component as you want
return (
<div>
{args.EmployeeID} - <MyComponentButton btnvalue={args.CustomerID} />
</div>
);
}
columns = [
{
field: 'OrderID',
headerText: 'Order ID',
width: 150
},
{
field: 'CustomerID',
headerText: 'Customer ID',
template: this.template,
width: 150
},
{ field: 'Freight', headerText: 'Freight', width: 150 },
{ field: 'ShipCity', headerText: 'Ship City', width: 150 }
];
render() {
return (
<div className="report-master-form">
<GridComponent
dataSource={hierarchyOrderdata}
columns={this.columns}
height={315}
/>
</div>
);
}
}
|
Hi Rajapandiyan,
Thanks a lot for this solution. This solved my problem.
Regards,
YM
Hi Rajapandiyan,
Thankyou for your previous response. I have another question. I am using React-TypeScript for this project. This is how I used custom Templates.
customTemplate=(props:any)=>{
return()
}
columns= column=[{ template: customTemplate }]
I am getting a TypeScript warning for using (props:any) .
I am also getting the following warning for using a template literal-
"Invalid type "any" of template literal expression"
What Datatype Should I use for props and template?
Thankyou
|
[App.tsx]
export default class App extends React.Component<{}, {}>{
template(props: Object) {
console.log(props);
return (
<div>
{props["EmployeeID"]}
</div>
);
}
public columns: Object[] = [
{
field: 'OrderID',
headerText: 'Order ID',
width: 150
},
{
field: 'CustomerID',
headerText: 'Customer ID',
template: this.template,
width: 150
},
{ field: 'Freight', headerText: 'Freight', width: 150 },
{ field: 'ShipCity', headerText: 'Ship City', width: 150 }
];
public render(){
return <GridComponent
dataSource={data}
columns={this.columns}
height={315}
/>
}
};
|