Hi,
I trying to incorporate Kendo React Components with an existing React SPA.
Trying I can successfully add a grid to a page, here is a snippet of my Component:
import * as React from 'react';import { Grid, GridColumn as Column, GridToolbar } from '@progress/kendo-react-grid';export const icon: string = "fa fa-grid";export const title: string = "Inline Grid";interface IData { id: string; name: string; description: string;}interface IState { data: Array<IData>;}interface IProps {};export class InlineEditGrid extends React.Component<IProps, IState> { constructor(props: IProps) { super(props); this.state = { data: [ { id: "00001", name: "Name", description: "Testing 1, 2, 3", } ] } } public render() { return ( <div className='row'> <div className='col-xs-12'> <Grid data={this.state.data}> <GridToolbar> <button title="Save Changes" className="k-button"> Save Changes </button> <button title="Cancel Changes" className="k-button"> Cancel Changes </button> </GridToolbar> <Column field="id" title="Id" width="50px" editable={false} /> <Column title="Product Name" width="150px" field="name" /> <Column title="Description" width="200px" field="description" /> </Grid> </div> </div> ); }}
The problem is, I doesn't detect the GridToolbar or the GridColumns, so my GridToolbar is not visible and my columns aren't formatted as required.
Troubleshooting the problem I took a peek into my node_modules folder under @progress\kendo-react-grid\dist\es\Grid.js to see how the Grid component detects GridToolbars and GridColumns. I found the following:
Grid.prototype.render = function () { ... var children = React.Children.toArray(this.props.children); this.initColumns(children.filter(function (child) { return child && child.type === GridColumn; })); var toolbar = children.filter(function (child) { return child && child.type === GridToolbar; }); ...}
As I am using Webpack to bundle my script files, including vendor imports, I has a look at the file Webpack generated script file to see how it was imported:
Grid.prototype.render = function () { ... this.initColumns(children.filter(function (child) { return child && child.type === _GridColumn__WEBPACK_IMPORTED_MODULE_3__["default"]; })); var toolbar = children.filter(function (child) { return child && child.type === _GridToolbar__WEBPACK_IMPORTED_MODULE_17__["default"]; }); ...}
As you can see Webpack has replaced the type references with it's own types, hence the conditional statements can never resolve to true.
What is the best wayto configure webpack so it can import Kendo React components with causing the above issues?
Thanks.
