Hi,
Using my own data, I could not make work the sort feature on the new DynamicTable. Weird behaviour.
So I checked it starting from the Hello World app, with the example provided in https://developer.atlassian.com/platform/forge/ui-kit/components/dynamic-table/
And it does not work. Or not always.
Using the whole set of data of the example, search by term has just 1 anomaly (1697 is placed by mistake between 1789 and 1801.
With a smaller set of data, it’s easier to see the problem: using the code below, sorted by Party, I get Democrat, aDemocrat and then Democrat.
This is the code I use:
import React from 'react';
import ForgeReconciler, { Text } from '@forge/react';
import { DynamicTable, Link } from "@forge/react";
const App = () => {
const presidents = [
{
id: 7,
name: "Andrew Jackson",
party: "Democrat",
term: "1829-1837",
},
{
id: 8,
name: "Martin van Buren",
party: "aDemocrat",
term: "1837-1841",
},
{
id: 11,
name: "James K. Polk",
party: "Democrat",
term: "1845-1849",
},
];
const createKey = (input) => {
return input ? input.replace(/^(the|a|an)/, "").replace(/\s/g, "") : input;
}
// applied as rows in the form
const rows = presidents.map((president, index) => ({
key: `row-${index}-${president.name}`,
cells: [
{
key: createKey(president.name),
content: <Link href="">{president.name}</Link>,
},
{
key: createKey(president.party),
content: president.party,
},
{
key: president.id,
content: president.term,
},
],
}));
const head = {
cells: [
{
key: "name",
content: "Name",
isSortable: true,
},
{
key: "party",
content: "Party",
shouldTruncate: true,
isSortable: true,
},
{
key: "term",
content: "Term",
shouldTruncate: true,
isSortable: true,
},
],
};
return (
<>
<Text>Hello world!</Text>
<DynamicTable
caption="List of US Presidents"
head={head}
rows={rows}
/>
</>
);
};
ForgeReconciler.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
Anyone else who could confirm that it does not work as is? @YY1 , I think you also had this problem. Is it a known bug at Atlassian?
In the meantime, I think I will disallow the sorting feature using a flag and an environment variable, so it will be easier to enable it when this problem is solved.