fix: number sort (#2508)

This commit is contained in:
Nathan.fooo 2023-05-11 18:35:51 +08:00 committed by GitHub
parent 2a35787dd1
commit a2b592a59b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View File

@ -243,7 +243,17 @@ impl TypeOptionCellDataCompare for NumberTypeOption {
cell_data: &<Self as TypeOption>::CellData, cell_data: &<Self as TypeOption>::CellData,
other_cell_data: &<Self as TypeOption>::CellData, other_cell_data: &<Self as TypeOption>::CellData,
) -> Ordering { ) -> Ordering {
cell_data.0.cmp(&other_cell_data.0) let left = NumberCellFormat::from_format_str(&cell_data.0, self.sign_positive, &self.format);
let right =
NumberCellFormat::from_format_str(&other_cell_data.0, self.sign_positive, &self.format);
match (left, right) {
(Ok(left), Ok(right)) => {
return left.decimal().cmp(&right.decimal());
},
(Ok(_), Err(_)) => Ordering::Greater,
(Err(_), Ok(_)) => Ordering::Less,
(Err(_), Err(_)) => Ordering::Equal,
}
} }
} }
impl std::default::Default for NumberTypeOption { impl std::default::Default for NumberTypeOption {

View File

@ -179,7 +179,7 @@ pub fn make_test_grid() -> DatabaseData {
for field_type in FieldType::iter() { for field_type in FieldType::iter() {
match field_type { match field_type {
FieldType::RichText => row_builder.insert_text_cell("DA"), FieldType::RichText => row_builder.insert_text_cell("DA"),
FieldType::Number => row_builder.insert_number_cell("4"), FieldType::Number => row_builder.insert_number_cell("14"),
FieldType::DateTime => row_builder.insert_date_cell( FieldType::DateTime => row_builder.insert_date_cell(
"1668704685", "1668704685",
None, None,

View File

@ -213,7 +213,7 @@ async fn sort_number_by_descending_test() {
let scripts = vec![ let scripts = vec![
AssertCellContentOrder { AssertCellContentOrder {
field_id: number_field.id.clone(), field_id: number_field.id.clone(),
orders: vec!["$1", "$2", "$3", "$4", "", "$5"], orders: vec!["$1", "$2", "$3", "$14", "", "$5"],
}, },
InsertSort { InsertSort {
field: number_field.clone(), field: number_field.clone(),
@ -221,7 +221,7 @@ async fn sort_number_by_descending_test() {
}, },
AssertCellContentOrder { AssertCellContentOrder {
field_id: number_field.id.clone(), field_id: number_field.id.clone(),
orders: vec!["$5", "$4", "$3", "$2", "$1", ""], orders: vec!["$14", "$5", "$3", "$2", "$1", ""],
}, },
]; ];
test.run_scripts(scripts).await; test.run_scripts(scripts).await;