diff --git a/frontend/rust-lib/flowy-database/src/services/field/type_options/number_type_option/number_type_option.rs b/frontend/rust-lib/flowy-database/src/services/field/type_options/number_type_option/number_type_option.rs index a055d6f0ee..e6bbf826b3 100644 --- a/frontend/rust-lib/flowy-database/src/services/field/type_options/number_type_option/number_type_option.rs +++ b/frontend/rust-lib/flowy-database/src/services/field/type_options/number_type_option/number_type_option.rs @@ -216,7 +216,17 @@ impl TypeOptionCellDataCompare for NumberTypeOptionPB { cell_data: &::CellData, other_cell_data: &::CellData, ) -> Ordering { - cell_data.0.cmp(&other_cell_data.0) + let left = NumberCellData::from_format_str(&cell_data.0, self.sign_positive, &self.format); + let right = + NumberCellData::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 NumberTypeOptionPB { diff --git a/frontend/rust-lib/flowy-database/tests/database/mock_data/grid_mock_data.rs b/frontend/rust-lib/flowy-database/tests/database/mock_data/grid_mock_data.rs index 17dedca664..391ce84cb5 100644 --- a/frontend/rust-lib/flowy-database/tests/database/mock_data/grid_mock_data.rs +++ b/frontend/rust-lib/flowy-database/tests/database/mock_data/grid_mock_data.rs @@ -161,7 +161,7 @@ pub fn make_test_grid() -> BuildDatabaseContext { for field_type in FieldType::iter() { match field_type { 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("1668704685"), FieldType::SingleSelect => { row_builder.insert_single_select_cell(|mut options| options.remove(0)) diff --git a/frontend/rust-lib/flowy-database/tests/database/sort_test/single_sort_test.rs b/frontend/rust-lib/flowy-database/tests/database/sort_test/single_sort_test.rs index 8f9b7f8356..f7179b8e7a 100644 --- a/frontend/rust-lib/flowy-database/tests/database/sort_test/single_sort_test.rs +++ b/frontend/rust-lib/flowy-database/tests/database/sort_test/single_sort_test.rs @@ -212,7 +212,7 @@ async fn sort_number_by_descending_test() { let scripts = vec![ AssertCellContentOrder { field_id: number_field.id.clone(), - orders: vec!["$1", "$2", "$3", "$4", "", "$5"], + orders: vec!["$1", "$2", "$3", "$14", "", "$5"], }, InsertSort { field_rev: number_field.clone(), @@ -220,7 +220,7 @@ async fn sort_number_by_descending_test() { }, AssertCellContentOrder { 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;