console-table-printer icon indicating copy to clipboard operation
console-table-printer copied to clipboard

feat: The Computed Column function is passed `row`, `index`, and `array`

Open DanKaplanSES opened this issue 1 year ago β€’ 2 comments

πŸ‘€What is this pr about?

The Computed Column function is passed row, index, and array. The latter two are new.

I modeled this change on JavaScript's map() callback parameter.

πŸš€ Changes

Before:

export interface ComputedColumn extends ColumnOptionsRaw {
  function: (arg0: any) => any;
}

After:

export interface ComputedColumn extends ColumnOptionsRaw {
  function: (arg0: any, index: number, array: any[]) => any;
}

array is a string[]. I'm not sure why anything in this file has an any type, but I used it here to follow conventions.

Along the way, I noticed that the addColumn and addColumns parameters may have the wrong types?

Related

  • #461
  • #462
  • #463

DanKaplanSES avatar Jan 31 '24 00:01 DanKaplanSES

I've decided to convert this to a draft because I'm not sure if the new values will be correct when rows are filtered and/or sorted (or what "correct" means in this context).

DanKaplanSES avatar Jan 31 '24 01:01 DanKaplanSES

@DanKaplanSES Could you split the PR in 3 different ones fixing 3 different Problems? One of them are okay to be merged rest would have some comments

ayonious avatar Apr 19 '24 08:04 ayonious