13

我已经将网格的工作示例放在一起,并希望将 IconMenu 添加到网格每一行的列中。我看到了图标按钮,但是当我单击它时,我没有看到菜单。下面是网格的代码。

有没有人设法从 material-ui获得与IconMenu一起使用的固定数据表

require('fixed-data-table/dist/fixed-data-table.css');

var React = require('react');
var PropTypes = React.PropTypes;
var FixedDataTable = require('fixed-data-table');
var Table = FixedDataTable.Table;
var Column = FixedDataTable.Column;

// Material-UI
let MenuItem = require('material-ui/lib/menus/menu-item');
let IconMenu = require('material-ui/lib/menus/icon-menu');
let IconButton = require('material-ui/lib/icon-button');
let Colors = require('material-ui/lib/styles/colors');
let MoreVertIcon = require('material-ui/lib/svg-icons/navigation/more-vert');

function cellMenuRenderer(cellData, key, rowData, rowIndex, columnData, width) {
    let button = (
        <IconButton
            touch={true}
            tooltip='Click to see menu.'
            tooltipPosition='bottom-left'>
            <MoreVertIcon color={Colors.grey400} />
        </IconButton>
    );
    return (
        <IconMenu iconButtonElement={button}>
            <MenuItem primaryText="Edit" />
            <MenuItem primaryText="New Test" />
            <MenuItem primaryText="Review" />
        </IconMenu>
    );
}

var SampleResultGrid = React.createClass({
    propTypes: {
        onContentDimensionsChange: PropTypes.func,
        left: PropTypes.number,
        top: PropTypes.number
    },

    getInitialState() {
        var jsonText = '[{"First":"Joe","Last":"Smith","Company":"Joe\'s Garage","Email":"joe@smith.com"},{"First":"Jill","Last":"Smithers","Company":"Jill\'l Rehab Center","Email":"jill@smithers.com"},{"First":"Brenda","Last":"Jones","Company":"Foodmart","Email":"brenda@jones.com"}]';
        let data = JSON.parse(jsonText);
        console.log(data);
        return {
            rows: data
        };
    },

    rowGetter(index) {
        return this.state.rows[index];
    },

    render() {
        return (
            <Table
                headerHeight={40}
                rowHeight={30}
                rowsCount={this.state.rows.length}
                rowGetter={this.rowGetter}
                width={800}
                height={500}>
                <Column
                    width={100}
                    cellRenderer={cellMenuRenderer}
                    align='center'
                    dataKey='Menu'
                    label='Menu'/>
                <Column
                    width={150}
                    dataKey='First'
                    label='First'/>
                <Column
                    width={150}
                    dataKey='Last'
                    label='Last'/>
                <Column
                    width={150}
                    dataKey='Company'
                    label='Company'/>
                <Column
                    width={150}
                    dataKey='Email'
                    label='Email'/>
            </Table>
        );
    }
});

module.exports = SampleResultGrid;
4

1 回答 1

0

要求('固定数据表/dist/固定数据表.css');

它不起作用,您必须在加载反应组件的 html 页面中提供此 css 参考。

于 2015-11-09T08:21:54.533 回答