AllenFang / react-bootstrap-table

A Bootstrap table built with React.js
https://allenfang.github.io/react-bootstrap-table/
MIT License
2.23k stars 782 forks source link

"TypeError: this.getColumnsDescription(...) is undefined" when attempting to functionally render TableHeaderColumn elements #1380

Open abd124abd opened 7 years ago

abd124abd commented 7 years ago

Hi, sorry if this doesn't belong here but not sure if I'm doing something wrong or there is something internally preventing the functional rendering of TableHeaderColumn elements. Am currently evaluating React table libraries for work with your library as the front-runner - for some reason have not seen any table library implemented with functional rendering of the column elements. Is there a specific reason why - am I just doing something wrong? Any help or guidance appreciated please.

TypeError: this.getColumnsDescription(...) is undefined

The code:

render() {

        // string constant names different from remote data keys
        const shopperTableColumnNamesKeys = Object.getOwnPropertyNames(ShopperTableColumnNames);

        // for...in does not preserve Object key order, create list instead
        const shopperRemoteDataKeys = Object.getOwnPropertyNames(shoppers[0]);

        const createInitialTableHeaderColumn = (key, index) => {
            return (
                <TableHeaderColumn
                    caretRender={this.getCaret}
                    columnClassName={this.columnClassNameFormat}
                    dataField={key}
                    dataSort={true}
                    key={index}
                    isKey={true}
                >
                    {ShopperTableColumnNames[shopperTableColumnNamesKeys[index]]}
                </TableHeaderColumn>
            );
        };

        const createTableHeaderColumn = (key, index) => {
            return (
                <TableHeaderColumn
                    caretRender={this.getCaret}
                    columnClassName={this.columnClassNameFormat}
                    dataField={key}
                    dataSort={true}
                    key={index}
                >
                    {ShopperTableColumnNames[shopperTableColumnNamesKeys[index]]}
                </TableHeaderColumn>
            );
        };

        const populateTableHeaderColumns = () => {
            const tableColumns = [];
            shopperRemoteDataKeys.forEach( (key, index) => {
                index === 0
                    ? createInitialTableHeaderColumn(key, index)
                    : createTableHeaderColumn(key, index);
                ;
            });
        };

        return (
            <div>
                <BootstrapTable
                    ref='rbt'
                    data={shoppers}
                    {...options}
                    {...tableProps}
                >
                    {populateTableHeaderColumns()}
                </BootstrapTable>
            </div>
        );
    }
AllenFang commented 7 years ago

you can use keyField on BootstrapTable which can avoid you write two function for rendering TableHeaderColumn. BTW, I'm first time that saw this issue and can;t not reproduce it. I'm not very sure what happen but I think this error should not being happen