Giter Site home page Giter Site logo

Comments (5)

shinima avatar shinima commented on May 3, 2024

这个可以在树状模式的基础上修改实现,我过会儿写个 demo

from ali-react-table.

shinima avatar shinima commented on May 3, 2024

我写了个 demo,你可以参考一下相关的代码。

在线 demo:示例-表格交互-单选与多选--树形选择

示例源码:

export function 树形选择() {
const [checkedKeys, setCheckedKeys] = useState<string[]>([])
const { dataSource: rawDataSource, isLoading } = useCityDataSource()
// 处理数据: 选取前 4 个省份,每个省份下选取 3 个城市
// 为每一行设置 name 作为展示名称;
// 为每一行数据设置 key,作为该行的主键;注意在相应的地方配置 primaryKey="key"
const dataSource = rawDataSource.slice(0, 4).map((prov) => ({
...prov,
name: prov.provinceName,
key: `prov:${prov.provinceName}`,
children: prov.children.slice(0, 3).map((city) => ({
...city,
name: city.cityName,
key: `city:${city.cityName}`,
})),
}))
const columns = [{ name: '省份/城市', code: 'name', width: 160 }, ...cols.indCols, cols.updateTime]
const renderData = applyTransforms(
{ dataSource, columns },
useTreeModeTransform({ primaryKey: 'key' }),
makeTreeSelectTransform({
// treeModeTransform 会对 dataSource 进行过滤,导致树不完整
// 这里要将 dataSource 传给 makeTreeSelectTransform,传递的树是完整的
tree: dataSource,
primaryKey: 'key',
value: checkedKeys,
onChange: setCheckedKeys,
checkboxColumn: { width: 48, lock: true },
// 可以省略 rootKey,此时将不会出现全选的 checkbox
rootKey: 'all',
// checkStrictly 可以设置为 true,此时父子节点的选中状态不再关联
checkStrictly: false,
// checkedStrategy 也可以设置为 all / child
checkedStrategy: 'parent',
}),
)
return (
<div>
<FusionStyles />
<p>
当前选中的 key 值:<code>{JSON.stringify(checkedKeys)}</code>
</p>
<BaseTable
primaryKey="key"
isLoading={isLoading}
dataSource={renderData.dataSource}
columns={renderData.columns}
/>
</div>
)
}

树状数据处理工具:
https://github.com/alibaba/ali-react-table/blob/0d92db89b6ed654c837d511eaca508044c4dae80/stories/examples/interactions/makeTreeDataHelper.tsx

from ali-react-table.

zjcwill avatar zjcwill commented on May 3, 2024

示例-表格交互-单选与多选--树形选择

感谢 demo补充

from ali-react-table.

zjcwill avatar zjcwill commented on May 3, 2024

我试了下 现在组件里没有暴露这个方法 makeTreeSelectTransform 版本为1.01
image

from ali-react-table.

shinima avatar shinima commented on May 3, 2024

我试了下 现在组件里没有暴露这个方法 makeTreeSelectTransform 版本为1.0

确实没有暴露,你先直接 copy 一下代码吧。

代码在这两个文件中:

ali-react-table 的定位是灵活的、高性能底层表格组件,像 makeTreeSelectTransform 这样的 API 可以在上层定制得到的话,ali-react-table 就不会再暴露这些 API 了。

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.