TanStack / table

πŸ€– Headless UI for building powerful tables & datagrids for TS/JS - React-Table, Vue-Table, Solid-Table, Svelte-Table
https://tanstack.com/table
MIT License
24.96k stars 3.07k forks source link

Manually create subRow structure without using a PivotBy #98

Closed vaidsu closed 7 years ago

vaidsu commented 7 years ago

I have an application where I am rendering a directory structure. I have created a recursive rendering using subcomponent and fetch data, where on every pivot expand of the subcomponent, it fetches the data as per the name and the re-renders a new subcomponent.

Here, every time I render the subcomponent I can easily render the whole react-table again. I wish to render just rows. Especially padded rows. No column headers.

I am trying different things while understanding the code.

So far I have tried to use TrComponent, TrGroupComponent, makePadRows directly but nothing has worked.

Sorry for posting a question in issue, any suggestion is appreciated.

Thanks.

tannerlinsley commented 7 years ago

Interesting. So basically you want to manually create indented sub rows with expander arrows? On Sat, Feb 25, 2017 at 7:28 PM Vaithiyanathan Sundaram < notifications@github.com> wrote:

I have an application where I am rendering a directory structure. I have created a recursive rendering using subcomponent and fetch data, where on every pivot expand of the subcomponent, it fetches the data as per the name and the re-renders a new subcomponent.

Here, every time I render the subcomponent I can easily render the whole react-table again. I wish to render just rows. Especially padded rows. No column headers.

I am trying different things while understanding the code.

So far I have tried to use TrComponent, TrGroupComponent, makePadRows directly but nothing has worked.

Sorry for posting a question in issue, any suggestion is appreciated.

Thanks.

β€” You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tannerlinsley/react-table/issues/98, or mute the thread https://github.com/notifications/unsubscribe-auth/AFUmCRyJQr3OKDI5_JmycmW9hDUwH3ERks5rgONLgaJpZM4MMNq3 .

vaidsu commented 7 years ago

Yes. Its a huge directory structure with lot of data integrated as a part of each person. So loading all the data upfront and pivoting them would be a performance issue.

So I made it fetch when click, which is free when I use subcomponent.

Please correct me if my assumptions are wrong:

Depending on my assumptions, I can pursue my experiments, if gaps found I am open to contribute back. I have design significant amount of requirements around your table, so I am open to stick to it and help grow :)

tannerlinsley commented 7 years ago

Awesome! I'm going to sleep on this and hopefully have a good solution path for you by Monday :) On Sat, Feb 25, 2017 at 8:28 PM Vaithiyanathan Sundaram < notifications@github.com> wrote:

Yes. Its a huge directory structure with lot of data integrated as a part of each person. So loading all the data upfront and pivoting them would be a performance issue.

So I made it fetch when click, which is free when I use subcomponent.

Please correct me if my assumptions are wrong:

  • Pivoting is done on pre-rendered data, i.e. the {data} we insert into ReactTable
  • I can extend TrRow and TrRowGroup, but cannot use them as a subcomponent.
  • If I have to pre-fetch data, either I should implement a click handler using your getProps example or async pre-fetch data as soon as the first data is loaded. But the latter would be a bit complex since I have to maintain more states.
  • If I extend the data state already existing, it would re-render the table with new dataset?

Depending on my assumptions, I can pursue my experiments, if gaps found I am open to contribute back. I have design significant amount of requirements around your table, so I am open to stick to it and help grow :)

β€” You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/tannerlinsley/react-table/issues/98#issuecomment-282529982, or mute the thread https://github.com/notifications/unsubscribe-auth/AFUmCTcS36R430Tv9qFGYHt3X7ASnUdzks5rgPFSgaJpZM4MMNq3 .

vaidsu commented 7 years ago

Thanks a lot. Just before I let you into that state, some data from my experiments.

[
{parent: 'abc', child: 'xyz'},
{parent: 'xyz', child: 'ttt'},
{parent: 'xyz', child: 'zzz'}
]

Now this is good enough, but there is a catch, I want xyz to also be inside the abc's (its parent's) pivot. That doesn't happen now obviously since the data is not like that. And currently AFAIK there is no way to say:

[
{parent: 'abc', 
child:  [
{parent: 'xyz', child: 'ttt'},
{parent: 'xyz', child: 'zzz'}
]
}

]

Is that a fair assumption?

tannerlinsley commented 7 years ago

I haven't been able to find a good solution for this problem yet. I've fiddled around with allowing manual subRows, but so far I haven't been able to make it work. That is most definitely the way the solution needs to go though. The dataModel logic and the render logic should be able to handle manually assembling your own subRow tree without pivotBy being used.

vaidsu commented 7 years ago

Thanks a lot of checking.

I did some experiments on my own too. Built a basic table to learn the art of appending rows like a linked list.

In that process, I found that, may be if the Row and the TrGroup/TrRow components are exported out, such that I can just add the Row Component as a subcomponent, would that be helpful?

Which is quoting: "I've fiddled around with allowing manual subRows"

On Tue, Feb 28, 2017 at 11:24 AM, Tanner Linsley notifications@github.com wrote:

I haven't been able to find a good solution for this problem yet. I've fiddled around with allowing manual subRows, but so far I haven't been able to make it work. That is most definitely the way the solution needs to go though. The dataModel logic and the render logic should be able to handle manually assembling your own subRow tree without pivotBy being used.

β€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tannerlinsley/react-table/issues/98#issuecomment-283137137, or mute the thread https://github.com/notifications/unsubscribe-auth/AQSdKYSoRAEzUQx6mMtEZPoFehmQkNmHks5rhHSFgaJpZM4MMNq3 .

aaronschwartz commented 7 years ago

I've been thinking about this too for my own needs.

I would love an API that looks something like this.

File directory list as example (This isn't my use case though):

        let data = [
            {
                dirName: "Projects",
                dirPath: "/home/projects",
                dirSize: "40mb",
                children: [
                    {
                        dirName: "project_1",
                        dirPath: "/home/projects/project_1",
                        dirSize: "30mb",
                        children: [
                            {
                                dirName: "sub_1",
                                dirPath: "/home/projects/project_1/sub_1",
                                dirSize: "20mb"
                            },
                            {
                                dirName: "sub_2",
                                dirPath: "/home/projects/project_1/sub_2",
                                dirSize: "10mb"
                            }
                        ]
                    },
                    {
                        dirName: "project_2",
                        dirPath: "/home/projects/project_2",
                        dirSize: "10mb"
                    }
                ]
            }
        ]
    }

    <ReactTable data={data} subrowAccessor={"children"}/>

I'm not sure if this would complicate the library too much.

tannerlinsley commented 7 years ago

I know I can make this happen. Just need to do another pass on it from scratch. It's just a matter of of:

milieux commented 7 years ago

Related: hiding the expander if there is no manual subrow.

aight8 commented 7 years ago

This feature would be awesome because I have exactly the same requirement. I tried several solutions but currently not found the best way to accomplish this.

Using SubComponent to render a sub table is currently the only solution to fulfill somehow the requirement. However it not benefits of the "one-table" advantages like the pivot functionality.

By the way I already tried with pivotBy but I recognised fast that it ends up in a static nested structure. My data items have an id property:

root.field1
root.field2
root.items.1.field3
root.items.2.field4

So the maximum I can accomplished was a table output like:

- undefined
   - field1
   - field2
- items.1
   - field3
   - field4

Beside the "subRow" method or however strategy, maybe a "dynamic pivot" (or call it table based tree! ;)) could be also a nice feature. So that the nesting are created dynamically per entry. Every item must provide it's parent.

Apropos... I think one picture says everything:

messages-attachments-folder-mac-osx

vaidsu commented 7 years ago

Hi all and @tannerlinsley sorry its been very very long since I came back to this thread. Apologies for delay.

However, I had some deliverables, so did some of my own solutions, and now ready to contribute back. I am using a combination of plain tables through Semantic UI react and React Table with search.

Essentially here are the features I implemented:

tannerlinsley commented 7 years ago

@vaidsu your questions:

@here, we have tested a few ways of accomplishing manual subRows (one of which is easily achieved by changing the subRowsKey to children and just nesting your rows inside of a children key in your rows. This opened up a pandoras box of edge cases and different uses that we weren't ready to put into v6, so we are going to leave this issue open and keep chipping away at the feature.

jehrlich commented 7 years ago

I'm not experienced enough in js or html to understand the full detail of what is being discussed here, but I see this as a need for a flexible cell-level subcomponent. That is, the current SubComponent functions at the row level and is very adaptable to all kinds of use cases there. Would it not be possible to design a similar interface at the cell level so that there is an expand icon attached to a cell which passes the cell data to something similar to SubComponent?

In my current case, each data row includes a cell with an array of 1..n sub-objects. My accessor writes a concatenated list of the names of the sub-objects, and the filter is easily adapted to search the array for any match. I first tried using the SubComponent to show a nested table of the expanded array. That was OK except it's really a cell-level, not row-level expansion, and I needed the row-level expansion for a different purpose (to display an html document generated from the row). So I want to be able to designate a cell as expandable, which will add an icon to the cell which, when clicked, will show a SubComponent which is passed the cell data.

I think what I am suggesting is that you simplify by adding a generic row-level subcomponent rather than building in full functionality from the start.

roginfarrer commented 7 years ago

Just want to comment that this is exactly a feature I'm looking for! Do you think we'll see this feature make into a future release?

tannerlinsley commented 7 years ago

I suspect you will, as this is technically being developed, but it won’t be very soon. :(

On Thu, Jul 6, 2017 at 7:43 AM Rogin Farrer notifications@github.com wrote:

Just want to comment that this is exactly a feature I'm looking for! Do you think we'll see this feature make into a future release?

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tannerlinsley/react-table/issues/98#issuecomment-313399836, or mute the thread https://github.com/notifications/unsubscribe-auth/AFUmCdI24WT8Qq_U-HVxk9TSSIaY8Esqks5sLOR6gaJpZM4MMNq3 .

davchang commented 7 years ago

Can we make SubComponent be dynamic? Currently once SubComponent shows up, it won't go away unless you re-launch the component.

example:

let subComponentAttr = {}
if (this.state.showSubComponent) {
  subComponentAttr = {
    SubComponent: (row) => console.log('showing showSubComponent...')
  }
} else {
  subComponentAttr = {}
}

return (
  <div>
    <button onClick={this.handleClick}>Click me</button>

    <ReactTable
      data={data}
      columns={columns}
      {...subComponentAttr}
    />
  </div>
)
tannerlinsley commented 7 years ago

@davchang Why not just click the arrow to hide the subComponent? Or use the fully controlled expanded and onExpandedChanged props?

davchang commented 7 years ago

Thank you for the great open source. I am now trying to use expanded and onExpandedChanged props.

When an user clicks an arrow, I want to append an empty div just like what SubComponent did. The snippet is not working. Am I missing anything?

const columns = [{
  Header: '',
  accessor: '', // String-based value accessors!
  expander: true,
  show: this.state.showSubComponent,
  getProps: (state, rowInfo, column) => {
    return {
      className: 'myFoo'
      style: {
        background: 'yellow'
      }
    }
  }
}, {
  Header: 'Name',
  accessor: 'name' // String-based value accessors!
}, {

… <ReactTable data={data} columns={columns} onExpandedChange={(newExpanded, index, event) => { return ( <div style={{padding: '20px'}}> It even has access to the row data:

) }}

tannerlinsley commented 7 years ago

This feature request is going into the deep freeze until the next major version. TBD

oowowaee commented 6 years ago

@tannerlinsley Seeing as how the status of this feature is unknown, could you expand on your solution mentioned here:

@here, we have tested a few ways of accomplishing manual subRows (one of which is easily achieved by changing the subRowsKey to children and just nesting your rows inside of a children key in your rows. This opened up a pandoras box of edge cases and different uses that we weren't ready to put into v6, so we are going to leave this issue open and keep chipping away at the feature.

pdrbrnd commented 6 years ago

Was this implemented in any new version?

oowowaee commented 6 years ago

@pbrandone I don't believe so, I had to go with transforming the data to a flat structure and pivoting on the parent key.

burgalon commented 6 years ago

any news here? Has anyone been able to get around this elegantly?

JohannesFischer commented 5 years ago

Would be interested in a solution too. Any news?

shamilium commented 5 years ago

@tannerlinsley can you give us a hope, please?

tannerlinsley commented 5 years ago

You will be able to do this in the next version.

shamilium commented 5 years ago

@tannerlinsley thanx! I see 7.0.0-alpha.0 already published, but no documentation yet. Can you give the cue what props to use? Excuse my annoyance.

tannerlinsley commented 5 years ago

It's not documented for that reason. The API is still in too much flux. If you want to to try the alpha you can use the codesandbox in the readme.

On Tue, Feb 5, 2019 at 8:57 AM Shamil notifications@github.com wrote:

@tannerlinsley https://github.com/tannerlinsley thanx! I see 7.0.0-alpha.0 already published, but no documentation yet. Can you give the cue what props to use? Excuse my annoyance.

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tannerlinsley/react-table/issues/98#issuecomment-460692215, or mute the thread https://github.com/notifications/unsubscribe-auth/AFUmCWspBvst227WbBwuZ_4883JYQzDzks5vKanggaJpZM4MMNq3 .

shamilium commented 5 years ago

I solved my problem (with version 6.8.6 of react-table) setting up subRowKey prop and adding expander column: <ReactTable data={this.props.incidentSteps} columns={columns} subRowsKey="child_steps"

@vaidsu did you try it? But I have to say that i need only one level of nesting.

lokeshnagpal commented 3 years ago

I want to display tree-view in column and expand/collapse showing with cell value in same column using react-table. As what i see react-table has tree-view with expand/collapse but not showing with value. Sharing the screenshot what I actually want. Please provide source code in react-table.

image