reactjs - 控制 react-data-table-component 列的宽度

标签 reactjs

我需要从“react-data-table-component”控制表格列的宽度。到目前为止,我正在使用它,但它不起作用。

const columns = [
{
  name: "ID",
  selector: "id",
  sortable: true,
  headerStyle: (selector, id) => {
    return { width: "80px", textAlign: "center" };
  },
},
{
  name: "Another column",
  selector: "blahblah",
  sortable: true,
},]

这是组件 -> https://www.npmjs.com/package/react-data-table-component

enter image description here

最佳答案

有点晚了,但对于 future 的读者来说,这是对我有用的。 使用问题中的原始代码,在与 name: "ID" 相同的级别添加 width: "80px" 会使其大小合适。

const columns = [
{
  name: "ID",
  selector: "id",
  sortable: true,
  width: "80px"                       // added line here
  headerStyle: (selector, id) => {
    return { textAlign: "center" };   // removed partial line here
  },
},
{
  name: "Another column",
  selector: "blahblah",
  sortable: true,
  width: "4rem"                       // another for example
},]

关于reactjs - 控制 react-data-table-component 列的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65778488/

相关文章:

javascript - 需要以前的 Prop 和状态回调的静态 getDerivedStateFromProps?

javascript - 从数组中删除所有具有特征 X 的元素,最新的除外

html - 如何让一个 React 组件占据整个屏幕(在所有设备上)直到您向下滚动?

Javascript,然后方法不等待React中的异步函数

css - 使用 Tailwind 时如何更改滚动条 (next.js/react)

javascript - 无法读取reactjs中未定义的属性 'sort'

node.js - 使用 MERN 堆栈构建 Web 应用程序与使用 Laravel(使用 React)构建 Web 应用程序有什么区别?

javascript - 如何更新数组中的 json 对象?

reactjs - 任何人都可以提供 React-Redux Jest 测试的示例吗?

reactjs - React props.children 宽度