mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Improve database table view template column sorting https://github.com/siyuan-note/siyuan/issues/9914
This commit is contained in:
parent
8363a3d811
commit
fe88ac105d
2 changed files with 20 additions and 0 deletions
|
|
@ -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:
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue