tree icon indicating copy to clipboard operation
tree copied to clipboard

Flat data for the tree

Open jerrygreen opened this issue 5 years ago • 3 comments

I want to have flat list of objects, more like a relational database, rather than real tree. But it has all the info for the tree:

const treeDataList = [
  {
    key: '0-0',
    title: 'parent 1',
    children: ['0-0-0', '0-0-1'],
  },
  {
    key: '0-0-0',
    title: 'parent 1-1',
    children: ['0-0-0-0'],
  },
  { key: '0-0-0-0', title: 'parent 1-1-0' },
  {
    key: '0-0-1',
    title: 'parent 1-2',
    children: [
      '0-0-1-0',
      '0-0-1-1',
      '0-0-1-2',
      '0-0-1-3',
      '0-0-1-4',
      '0-0-1-5',
      '0-0-1-6',
      '0-0-1-7',
      '0-0-1-8',
      '0-0-1-9',
    ],
  },
  { key: '0-0-1-0', title: 'parent 1-2-0' },
  { key: '0-0-1-1', title: 'parent 1-2-1' },
  { key: '0-0-1-2', title: 'parent 1-2-2' },
  { key: '0-0-1-3', title: 'parent 1-2-3' },
  { key: '0-0-1-4', title: 'parent 1-2-4' },
  { key: '0-0-1-5', title: 'parent 1-2-5' },
  { key: '0-0-1-6', title: 'parent 1-2-6' },
  { key: '0-0-1-7', title: 'parent 1-2-7' },
  { key: '0-0-1-8', title: 'parent 1-2-8' },
  { key: '0-0-1-9', title: 'parent 1-2-9' },
]

Does rc-tree support such a flat shape? Ofc, I may make some additional layer myself, so original data will stay flat, but for the tree I'll have this additional layer which will be actual tree. But I'm wondering if it's already supported, because, well... It looks like a pretty much common case.

If it's not supported, what do you think about this idea?

jerrygreen avatar Mar 19 '20 13:03 jerrygreen

it is used internally https://github.com/react-component/tree/blob/master/src/Tree.tsx#L289 so it's just a matter of being properly exposed Screenshot from 2020-08-04 10-58-40

Dmitra avatar Aug 04 '20 07:08 Dmitra

I want to have flat list of objects, more like a relational database, rather than real tree. But it has all the info for the tree:

const treeDataList = [
  {
    key: '0-0',
    title: 'parent 1',
    children: ['0-0-0', '0-0-1'],
  },
  {
    key: '0-0-0',
    title: 'parent 1-1',
    children: ['0-0-0-0'],
  },
  { key: '0-0-0-0', title: 'parent 1-1-0' },
  {
    key: '0-0-1',
    title: 'parent 1-2',
    children: [
      '0-0-1-0',
      '0-0-1-1',
      '0-0-1-2',
      '0-0-1-3',
      '0-0-1-4',
      '0-0-1-5',
      '0-0-1-6',
      '0-0-1-7',
      '0-0-1-8',
      '0-0-1-9',
    ],
  },
  { key: '0-0-1-0', title: 'parent 1-2-0' },
  { key: '0-0-1-1', title: 'parent 1-2-1' },
  { key: '0-0-1-2', title: 'parent 1-2-2' },
  { key: '0-0-1-3', title: 'parent 1-2-3' },
  { key: '0-0-1-4', title: 'parent 1-2-4' },
  { key: '0-0-1-5', title: 'parent 1-2-5' },
  { key: '0-0-1-6', title: 'parent 1-2-6' },
  { key: '0-0-1-7', title: 'parent 1-2-7' },
  { key: '0-0-1-8', title: 'parent 1-2-8' },
  { key: '0-0-1-9', title: 'parent 1-2-9' },
]

Does rc-tree support such a flat shape? Ofc, I may make some additional layer myself, so original data will stay flat, but for the tree I'll have this additional layer which will be actual tree. But I'm wondering if it's already supported, because, well... It looks like a pretty much common case.

If it's not supported, what do you think about this idea?

I have the same problem. It doesn't support the flat shape.How did you resolve it?

LazyChun avatar Sep 13 '21 15:09 LazyChun

We currently have an implementation that lazy loads each folder, but it's difficult to auto-expand to the correct leaf. We're also looking for this functionality as we could make the data come flat from our GraphQL API, then it would be much easier to get all data as a flat list, and auto-expand to the correct leaf in one go.

harrytalbot avatar Sep 14 '21 11:09 harrytalbot