nicolaskruchten / pivottable

Open-source Javascript Pivot Table (aka Pivot Grid, Pivot Chart, Cross-Tab) implementation with drag'n'drop.
https://pivottable.js.org/
MIT License
4.36k stars 1.08k forks source link

Custom sorting or formating #707

Open svpace opened 7 years ago

svpace commented 7 years ago

I have a 'type' dimension, with values 'credit' and 'debit' and another 'severity' dimension with values 'high', 'medium' and 'low'. To properly sort these keys a 'high' 'debit' is less than a 'low' 'debit' that is less than 'low' 'credit' that is less than 'high' 'credit', like the table below:

debit credit
high medium low low medium high

Unfortunately I've not been able to reach this result with sorters since sorting severites requires knowing the associated type.

Alternatively I've tried to replace severites with numeric values (-3, -2, -1, 1, 2, 3), but could not found a way to "format" the numbers into their proper values (high, medium, low).

Any ideas?

nicolaskruchten commented 7 years ago

Unfortunately, I don't think this will be possible directly, as nothing in the system works cross-attribute like this: every attribute is treated separately.

The only thing I can recommend is to concatenate your type and severity fields with a dash or something, and use a sorter, such that debit-high is less than credit-low etc

svpace commented 7 years ago

Thanks for the quick reply.

Regarding my second approach, using negative numbers. Is there any way to replace the numbers with the the severity keys for viewing only (ie replace -1 => high)?

nicolaskruchten commented 7 years ago

There is no built-in way to do this, no, but of course you may hack the existing renderers or create new ones :)

svpace commented 7 years ago

My thoughts exactly :) I will try to look it on the weekend. Any hints or warnings?

nicolaskruchten commented 7 years ago

Shouldn't be that hard... there's a documentation page in the wiki and you can look at the source for the existing ones for inspiration :)

On Thu, May 11, 2017 at 12:30 svpace notifications@github.com wrote:

My thoughts exactly :) I will try to look it on the weekend. Any hints or warnings?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/nicolaskruchten/pivottable/issues/707#issuecomment-300844284, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMbA-jk9mRuVGDMzb_2udq-wD-FKEu0ks5r4zeIgaJpZM4NWEPV .

svpace commented 7 years ago

Finally had time to prepare a proper PR :) Here is my take on the second approach we discussed. Instead of rewriting the entire table renderer I've added two functions to the rendererOptions to handle cell content rendering. I've used those to solve the original and also to include icons and custom markup to the main data

Murtagy commented 4 years ago

@svpace could you explain briefly how to use your PR? I know it is old enough, but may be you still have an example. I am not JS fluent, so I struggle with pivots