Tables are so amazing - in how they allow you to both display and edit whatever data your resource query spits out.
If transposed...you get an editable Key-Value like component...which is so useful for so many internal tools that need to display a single record and allow the user to edit its fields.
All the features required already exist within the current Table component. It's a purely visual transposition!
Either I'm going crazy and it doesn't exist - or the universe is. Lol.
@Arjun I agree, in theory if you could click a checkbox which transposed the table, so that the columns ran down the left, and the values along the top, it would be great.....however on reflection I think the coding would actually be quite heavyweight (from my limited software dev experience). Also, the difference between just transposing, and aggregating - pivot tables can be used to transpose but they are really designed for aggregating, and only really designed for numerical data.
That said, it took me a year to work out how to implement a pivot table custom component, I've now implemented it in a module and I just drop it in to whichever app I need a table in. I'll try and paste the updated code, it is a bit of effort but it's really 'do once'.
Hi @mondob Thanks for checking in! Unfortunately, I don't see this on our immediate roadmap but we are still tracking interest for this feature -- I'll add your +1 to the internal request
A transposed table, with the heading/key names running down the leftmost column and "rows" running down subsequent columns, so the table builds up from left to right (instead of top to bottom) would be very useful.
It's the kind of table preferred, and common, in booking systems where you have resources listed in the left column and allocation/availability (often date-wise) running left to right.
Below also is a javascript (thanks mainly to ChatGPT ) which can be used as a transformer on the result of a normal query to show a transposed version in a regular table.
The original headings, which should be transposed to the first column, likely show up in the wrong place initially, so will need to be re-positioned to the first column position.
Also it's not practical for tables which get updated often with new rows because then you have to manually tell the table to regenerate columns. But it's interesting as an example and could be useful for displaying some relatively static information.
(Since I had dates in the table I played safe and converted them to strings. So other tweaks could be necessary depending on data types in use).
let arr = formatDataAsArray(data);
if (arr.length === 0) return [];
const firstKey = Object.keys(arr[0])[0]; // Get the first key (e.g., "a")
const keys = Object.keys(arr[0]); // Get all keys from the first object
const newKeys = [firstKey, ...arr.map(obj => obj[firstKey])]; // Extract new keys
const transposed = [];
for (let i = 1; i < keys.length; i++) { // Skip the first key
let newRow = { [firstKey]: keys[i] }; // First key holds the column identifier
for (let j = 0; j < arr.length; j++) {
let value = arr[j][keys[i]];
// Convert Date objects to YYYY-MM-DD format
if (value instanceof Date) {
value = value.toISOString().split("T")[0];
}
newRow[newKeys[j + 1]] = value; // Assign value using the correct key
}
transposed.push(newRow);
}
return transposed;