datatable icon indicating copy to clipboard operation
datatable copied to clipboard

Need to be able to update master when working with subset

Open tomas-kucera opened this issue 3 years ago • 3 comments

Hi there,

Love the datatable concept. One thing that I am currently missing is the ability to update master/superset table while working with data in subset.

An example is: Master table: timestamp, portfolio_id, portfolio_group, amount

Subset table:

  • the same columns
  • records filtered using subset := master.Where ... timestamp & portfolio_group

I do some more complex operations on the subset and record results for it in the subset.

Now I need to propagate it to the master table.

So, it would be great to know the row index of the row or that the row subset would be a collection of pointers and would update the master directly when doing subset.Update ...

Or maybe I am missing something. I am not that proficient in Golang yet and there is very little documentation and even less can be found on the net.

Thanks for the great tool and hope that you can help me.

tomas-kucera avatar Mar 18 '21 22:03 tomas-kucera

Hi @tomas-kucera sorry for the delay. We did not get any notification from GH about your posted issue. Are you talking about a "nested table" concept ? Do you have an explicit example of what you want to do?

Best regards

lfroment-datasweet avatar Mar 30 '21 14:03 lfroment-datasweet

Hi, no problem!

The case is this:

  • have a table with many rows
  • you use .Where to create a subset of rows, storing it into another datatable
  • now I am going through the subset and making modifications
  • what I want is the modifications to be propagated to the table I had created the subset from
  • I did not find a way to do it via references, so the subset is a new copy and modifying it leave the original datatable unchanged
  • to be able to update a record you need to know its index in the datatable
  • since there is no way to read the index of the record, it is impossible to achieve directly

I had workarounded it by creating an explicit field called index that I populate with a sequence number and then when I need to update the original table I use this index in the .Update method. This works OK but has one catch - if you apply sorting or remove some rows, adds some rows, etc. you need to re-index it again, to get it consistent.

Still being able to create a subset using .Where that keep "connected" to the original datatable, so whenever I would update a row in the subset, it would update the original row.

Of course that it should be possible to create a subset as a new copy of data detaching it from the original datatable.

Is it clearer now? ;)

tomas-kucera avatar Apr 09 '21 12:04 tomas-kucera

Hi @tomas-kucera

Thx for you feedback. Indeed,

  • for now we don't provide an easy way to create en index. You can use the hasher (hasher.go).
  • the .Where indeed creates a new subset with copy. It could be a good enhancement to keep the sync.

charlotth avatar Apr 13 '21 08:04 charlotth