简体   繁体   English

调整反应表大小

[英]Resize React Table

I'm trying to build a webpage with a React Table and I cannot figure out how to resize the table such that it does not take up the whole page. 我正在尝试使用React Table构建网页,但无法弄清楚如何调整表的大小,以使其不占用整个页面。 Is this something that needs to be done in CSS or can it be rendered in React? 这是需要在CSS中完成的事情还是可以在React中呈现? I'm using create-react-app. 我正在使用create-react-app。 Thanks for the help. 谢谢您的帮助。 Here are my App.js and App.css files: 这是我的App.js和App.css文件:

App.js: App.js:

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {value: ''};

    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleChange(event) {
    this.setState({value: event.target.value});
  }

  handleSubmit(event) {
    alert('A name was submitted: ' + this.state.value);
    event.preventDefault();
  }

  render() {

  const data = [{
    name: 'Tanner Linsley',
    age: 26,
    friend: {
      name: 'Jason Maurer',
      age: 23,
    }
  }]

  const columns = [{
    Header: 'Username/Email',
    accessor: 'name' // String-based value accessors!
  }, {
    Header: 'Risk Score',
    accessor: 'age',
    Cell: props => <span className='number'>{props.value}</span> // Custom cell components!
  }, 

  {
    id: 'friendName', // Required because our accessor is not a string
    Header: 'Location',
    accessor: d => d.friend.name // Custom value accessors!
  }]

  return <ReactTable
    data={data}
    columns={columns}
  />
  }
}

export default App;

App.css: App.css:

.App {
  text-align: center;
  label{
    font-size: 26px;
  }
}

.App-logo {
  animation: App-logo-spin infinite 20s linear;
  height: 40vmin;
}

.App-header {
  background-color: #282c34;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: calc(10px + 2vmin);
  color: white;
}

.App-link {
  color: #61dafb;
}

@keyframes App-logo-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

:local(.form) {
  font-size: 26px;
}

/*:local(.ReactTable) {
  border: 1px solid black; 
  overflow:auto;
}*/

React table uses flex value 1. If you want to resize the table you need to override the default class or able to give props value. React表使用flex值1。如果要调整表的大小,则需要覆盖默认类或能够提供props值。 Please go through the documents to know more. 请仔细阅读文件以了解更多信息。

React Table Documentation 反应表文档

for example if you override class 例如,如果您覆盖类

.ReactTable.-striped.-highlight {
    width: 532px;
}

Please be cautious and modify according to your need. 请谨慎并根据您的需要进行修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM