2017-02-09 76 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山坳