Sort rows based on the positions of the values of a selector type attribute (not alphabetically) #859
lorensansol
started this conversation in
Ideas
Replies: 1 comment
-
Currently the sorting function is this one const dbfolderColumnSortingFn: (
ddbbConfig: LocalSettings
) => SortingFn<RowDataType> =
/**
* Custom sorting function for the dbfolder column. Global target
* @param ddbbConfig required to parse correctly Dates
* @returns
*/
(ddbbConfig: LocalSettings) =>
(
rowA: Row<RowDataType>,
rowB: Row<RowDataType>,
columnId: string
): number => {
const cellA = rowA.getValue<Literal>(columnId);
const cellB = rowB.getValue<Literal>(columnId);
// If both are numbers, compare as numbers
if (!Number.isNaN(Number(cellA)) && !Number.isNaN(Number(cellB))) {
return Number(cellA) - Number(cellB);
}
// If both are strings, compare as strings
const a = ParseService.parseLiteral(
cellA,
InputType.SORTING,
ddbbConfig,
true
)
.toString()
.toLowerCase();
const b = ParseService.parseLiteral(
cellB,
InputType.SORTING,
ddbbConfig,
true
)
.toString()
.toLowerCase();
// String comparison
return a === b ? 0 : a > b ? 1 : -1;
}; So we have to modify the value of the select of tag in sorting time. As an idea we can add the position ad the start, but it could be tricky because it affects to the written value inside the final note. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I think it would be great, in the DB Folder plugin, to have the ability to sort rows based on the positions of the values of a selector type attribute (not alphabetically), just like it's possible in Notion for state attributes.
A practical example for this could be for a list of projects or clients where the states "contact, budget, wait, execute, deliver, collect, finished..." are indicated and it is important that they appear in that order, without the need to add a number in front of them so that they are ordered alphabetically correctly.
Beta Was this translation helpful? Give feedback.
All reactions