Giter Club home page Giter Club logo

Comments (2)

shinima avatar shinima commented on May 4, 2024

如果你的 headerCellProps 都是有规律的话,你可以先自己实现一个处理函数,然后遍历一边所有的 columns 就好了。

import { BaseTable } from 'ali-react-table'
import { transformColumn, applyTransforms } from 'ali-react-table/biz'

// 根据列配置 有规律的生成 headerCellProps
function getHeaderCellProps(col) {
  const background = col.code.startsWith('amount_') ? 'red' : 'green'
  const fontSize = col.features.sortable ? 16 : 12

  return { ...col, headerCellProps: { style: { background, fontSize } } }
}

function MyComponent() {
  // 利用 transformColumn 来生成 transform,transformColumn 会正确处理嵌套的 columns
  const headerCellPropsTransform = transformColumn(getHeaderCellProps)

  const renderData = applyTransforms(
    { dataSource: inputDataSource, columns: inputColumns },
    transform_x,
    headerCellPropsTransform,
    transform_y,
  )

  return <BaseTable dataSource={renderData.dataSource} columns={renderData.columns} />
}

相关文档:
表格功能拓展-文档--page#统一拓展机制


一个 column 对应多个 表格数据单元格,所以表格设计了回调函数的方式来获取 数据单元格的 props。
而一个 column 只会有一个 表头单元格,headerCellProps 已经能够满足自定义 表头单元格props 的能力了,所以就不需要使用更复杂的函数的形式了。

from ali-react-table.

arcsin1 avatar arcsin1 commented on May 4, 2024

很赞 谢谢 解答!

from ali-react-table.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.