Sorting and displaying columns by different metrics

I've got two cases where I've run into a similar issue:

  • I have an column that displays HTML, and I want to sort by the HTML text, not the HTML url
  • I have a column that displays an approximate number to two significant digits in a readable format (1.1k, 36, 910k, 190), but I want to be able to sort it numerically

In both cases, the "Mapped value" feature doesn't do what I want.

In the first case, I could have the unmapped value be the string, the mapped value be the HTML, and sort by unmapped value... but then where do I get the URL from to make the mapped value?

In the second case, it almost works to have the "approximater" be the mapping, and sort by unmapped value... but because I want to set the property type to "text," it appears to apply that to both the mapped and unmapped value.

What I feel like I want is one of two things:

  • Either "secretly sort this column as if it was this other, hidden, column"
  • An ability to map one way for sorting, and another way for display, and possibly with those two having different types.

Is there a workaround that other people have found?

Hey @rob_at_brilliant!

I think this might be doable if you actually combine the two ideas! Using some JS you can add an additional column to your data whose underlying data you'd like to sort by, but whose mapper references your original column instead of itself. Then you can hide the original column.

Take the this example for instance. Assuming your original data is [1100, 36, 910000, 190]:

Create a new column whose underlying values are mapped to their sorting values, and attach it to the original data. In this case, it'll be fixed-length number strings left-padded with 0s:

Then pass the full set of data to your table and hide the original row:

Finally, you can still reference the original row in the mapper for the display row:

So, the added column has the mappings both for displaying and sorting, while the original column remains hidden.

Does that work?


Hmm, I think so! Left-padding with zeroes is the ugly hack that my mind refused to think about :melting_face:. But I think I can use that to make our case work!