Browse Source

:bug: Database table view sorts abnormally after deleting numeric values Fix https://github.com/siyuan-note/siyuan/issues/10476

Daniel 1 năm trước cách đây
mục cha
commit
a650764c12
2 tập tin đã thay đổi với 29 bổ sung1 xóa
  1. 24 0
      kernel/av/table.go
  2. 5 1
      kernel/model/attribute_view.go

+ 24 - 0
kernel/av/table.go

@@ -101,6 +101,18 @@ func (value *Value) Compare(other *Value) int {
 		}
 	case KeyTypeNumber:
 		if nil != value.Number && nil != other.Number {
+			if value.Number.IsNotEmpty {
+				if !other.Number.IsNotEmpty {
+					return 1
+				}
+				return 0
+			} else {
+				if other.Number.IsNotEmpty {
+					return -1
+				}
+				return 0
+			}
+
 			if value.Number.Content > other.Number.Content {
 				return 1
 			} else if value.Number.Content < other.Number.Content {
@@ -111,6 +123,18 @@ func (value *Value) Compare(other *Value) int {
 		}
 	case KeyTypeDate:
 		if nil != value.Date && nil != other.Date {
+			if value.Date.IsNotEmpty {
+				if !other.Date.IsNotEmpty {
+					return 1
+				}
+				return 0
+			} else {
+				if other.Date.IsNotEmpty {
+					return -1
+				}
+				return 0
+			}
+
 			if value.Date.Content > other.Date.Content {
 				return 1
 			} else if value.Date.Content < other.Date.Content {

+ 5 - 1
kernel/model/attribute_view.go

@@ -2534,10 +2534,14 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, rowID, cellID string,
 
 	if av.KeyTypeNumber == val.Type {
 		if nil != val.Number && !val.Number.IsNotEmpty {
-			// 删除内容为空值
 			val.Number.Content = 0
 			val.Number.FormattedContent = ""
 		}
+	} else if av.KeyTypeDate == val.Type {
+		if nil != val.Date && !val.Date.IsNotEmpty {
+			val.Date.Content = 0
+			val.Date.FormattedContent = ""
+		}
 	}
 
 	relationChangeMode := 0 // 0:不变(仅排序),1:增加,2:减少