2017-02-09 45 views
0

我使用的是被Facebook在这里显现的例子:https://facebook.github.io/fixed-data-table/example-resize.html固定数据表调整例如:无法调整列宽

的源代码(我用“老”的风格,与React.createClass)就在这里:https://github.com/facebook/fixed-data-table/blob/master/examples/old/ResizeExample.js#L35

我已经改变了我的代码了一下。我可以解析我的数组到细胞中,这很好。但是,能够拖动列的整个功能不起作用:鼠标确实正确地拖动列行的动画(如第一个示例中那样),但它从不“粘住”。是什么赋予了?

这是一些示例代码。也许我在状态处理方面做错了什么?

var FixedDataTable = require('fixed-data-table'); 
var React = require('react'); 

var Column = FixedDataTable.Column; 
var Table = FixedDataTable.Table; 
var Cell = FixedDataTable.Cell; 

var isColumnResizing; 

var columnWidths = { 
    firstName: 100, 
    lastName: 100, 
    address: 100, 
}; 
const TextCell = ({rowIndex, data, col, ...props}) => (
    <Cell {...props}> 
     {data[rowIndex][col] ? data[rowIndex][col] : " "} 
    </Cell> 
); 


var peopleTable = React.createClass({ 
    getInitialState() { 
     return { 
      columnWidths: columnWidths 
     } 
    }, 

    _onColumnResizeEndCallback(newColumnWidth, dataKey) { 
     var columnWidths = this.state.columnWidths; 
     columnWidths[dataKey] = newColumnWidth; 
     isColumnResizing = false; 
     this.setState({ 
      columnWidths 
     }) 
    }, 

    render() { 
     if (!this.props.data || !this.props.data.peopleInfo) { 
      return <div>No people found</div>; 
     } 

     var peopleMap = this.props.data.peopleInfo; 

     var peopleMapArr = Object.values(peopleMap).map(function(people) { 
      return people; 
     }); 

     // Here, it will print the array just fine. So it isn't related to that. 


     return (
      <div> 
       <Table 
        height={35 + ((peopleMapArr.length) * 80)} 
        width={750} 
        rowsCount={peopleMapArr.length} 
        rowHeight={80} 
        isColumnResizing={isColumnResizing} 
        onColumnResizeEndCallback={this._onColumnResizeEndCallback} 
        headerHeight={30} 
        {...this.props}> 
        <Column 
         header={<Cell>First Name</Cell>} 
         cell={<TextCell data={peopleMapArr} col="firstName" />} 
         fixed={true} 
         width={columnWidths['firstName']} 
         isResizable={true} 
         minWidth={100} 
         maxWidth={250} 
        /> 
        <Column 
         header={<Cell>Last Name</Cell>} 
         cell={<TextCell data={peopleMapArr} col="lastName" />} 
         width={columnWidths['lastName']} 
         isResizable={true} 
         minWidth={100} 
         maxWidth={250} 
        /> 
        <Column 
         header={<Cell>Address</Cell>} 
         cell={<TextCell data={peopleMapArr} col="address" />} 
         width={columnWidths['address']} 
         isResizable={true} 
         minWidth={100} 
         maxWidth={250} 
        /> 
       </Table> 
      </div> 
     ); 
    } 
}); 

module.exports = peopleTable; 

(这是一个示例)

我已经修改了一些东西,使其在从我的后台收集数据方面的工作,但它的工作原理,并正确显示。唯一不起作用的功能是拖动列(如facebook调整示例)。原因是什么?

回答

1

您需要的dataKey属性在_onColumnResizeEndCallback功能添加到每个列或更改dataKey山坳