🎨 Improve database table view template column sorting https://github.com/siyuan-note/siyuan/issues/9914

This commit is contained in:
Daniel 2023-12-18 19:17:04 +08:00
parent 8363a3d811
commit fe88ac105d
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 20 additions and 0 deletions

View file

@ -21,6 +21,8 @@ import (
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"github.com/siyuan-note/siyuan/kernel/util"
) )
// LayoutTable 描述了表格布局的结构。 // LayoutTable 描述了表格布局的结构。
@ -174,6 +176,18 @@ func (value *Value) Compare(other *Value) int {
} }
case KeyTypeTemplate: case KeyTypeTemplate:
if nil != value.Template && nil != other.Template { 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) return strings.Compare(value.Template.Content, other.Template.Content)
} }
case KeyTypeCheckbox: case KeyTypeCheckbox:

View file

@ -18,6 +18,7 @@ package util
import ( import (
"bytes" "bytes"
"strconv"
"strings" "strings"
"unicode" "unicode"
@ -82,3 +83,8 @@ func RemoveRedundantSpace(str string) string {
} }
return buf.String() return buf.String()
} }
func IsNumeric(s string) bool {
_, err := strconv.ParseFloat(s, 64)
return err == nil
}