Code Monkey home page Code Monkey logo

Comments (6)

ChipmunkJerry avatar ChipmunkJerry commented on May 2, 2024

oh我暂时找到了internals 感动!我继续尝试

from ali-react-table.

shinima avatar shinima commented on May 2, 2024

可以通过写一个类似makeSortTransform方法来实现筛选吗?

可以的

clumns该如何处理?

一般来说 需要自行对 columns 进行遍历;ali-react-table 也提供了 traverseColumn 来辅助对 columns 的遍历操作

from ali-react-table.

shinima avatar shinima commented on May 2, 2024

以下代码仅供思路参考:

function makeFilterTransform({ filterState, onChangeFilterState }) {
  return ({ columns, dataSource }) => {
    // 根据 filterState 来过滤数据源
    const filteredDataSource = dataSource.filter((row) => test(filterState, row))

    // 遍历 columns,在每一列的表头生成一个 过滤的图标,点击图表弹出过滤面板
    // 注意 columns 是一个嵌套的结构,一般情况下得用递归来进行遍历
    const nextColumns = columns.map((col) => {
      if (!col.features?.showFilter){
        // 只有 features.showFilter 的列才支持过滤
        return col
      }
      const name = col.name
      return {
        ...col,
        title: (
          <div>
            {name}
            <FilterIcon
              onClick={() => {
                showFilterPopup(col.code)
              }}
            />
          </div>
        ),
      }
    })

    return { dataSource: filteredDataSource, columns: nextColumns }
  }
}

// 在使用时……

const [filterState, onChangeFilterState] = useState([])

const renderData = applyTransforms(
  { dataSource, columns },
  makeFilterTransform({ filterState, onChangeFilterState }),
  makeSortTransform(...)
)

from ali-react-table.

ChipmunkJerry avatar ChipmunkJerry commented on May 2, 2024

非常感谢你的回答,功能可以很好的实现

from ali-react-table.

shinima avatar shinima commented on May 2, 2024

@ChipmunkJerry 我写了个 demo 你可以参考下: 示例-表格交互-筛选--筛选

实现起来还是比较麻烦的,代码在这里

from ali-react-table.

ChipmunkJerry avatar ChipmunkJerry commented on May 2, 2024

嗯嗯感谢,很详细,值筛选这个也很棒我都没想到
applyTransforms这种拓展方式挺好用的,再次感谢

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.