diff --git a/kernel/av/table.go b/kernel/av/table.go index c518ad4c0..66b297757 100644 --- a/kernel/av/table.go +++ b/kernel/av/table.go @@ -21,6 +21,8 @@ import ( "sort" "strconv" "strings" + + "github.com/siyuan-note/siyuan/kernel/util" ) // LayoutTable 描述了表格布局的结构。 @@ -174,6 +176,18 @@ func (value *Value) Compare(other *Value) int { } case KeyTypeTemplate: if nil != value.Template && nil != other.Template { + if util.IsNumeric(value.Template.Content) && util.IsNumeric(other.Template.Content) { + v1, _ := strconv.ParseFloat(value.Template.Content, 64) + v2, _ := strconv.ParseFloat(other.Template.Content, 64) + if v1 > v2 { + return 1 + } + + if v1 < v2 { + return -1 + } + return 0 + } return strings.Compare(value.Template.Content, other.Template.Content) } case KeyTypeCheckbox: diff --git a/kernel/util/misc.go b/kernel/util/misc.go index 9eea724d7..ef6623fcd 100644 --- a/kernel/util/misc.go +++ b/kernel/util/misc.go @@ -18,6 +18,7 @@ package util import ( "bytes" + "strconv" "strings" "unicode" @@ -82,3 +83,8 @@ func RemoveRedundantSpace(str string) string { } return buf.String() } + +func IsNumeric(s string) bool { + _, err := strconv.ParseFloat(s, 64) + return err == nil +}