🎨 Improve database field sorting Fix https://github.com/siyuan-note/siyuan/issues/11038
This commit is contained in:
parent
483ae3b671
commit
a049eeec3e
2 changed files with 21 additions and 11 deletions
|
@ -119,13 +119,19 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
|
|||
return 0
|
||||
}
|
||||
case KeyTypeSelect, KeyTypeMSelect:
|
||||
if 0 < len(value.MSelect) && 0 < len(other.MSelect) {
|
||||
v1 := value.MSelect[0].Content
|
||||
v2 := other.MSelect[0].Content
|
||||
if v1 == v2 {
|
||||
return 0
|
||||
if nil != value.MSelect && nil != other.MSelect {
|
||||
var v1 string
|
||||
for _, v := range value.MSelect {
|
||||
v1 += v.Content
|
||||
break
|
||||
}
|
||||
var v2 string
|
||||
for _, v := range other.MSelect {
|
||||
v2 += v.Content
|
||||
break
|
||||
}
|
||||
|
||||
// 按设置的选项顺序排序
|
||||
key, _ := attrView.GetKey(value.KeyID)
|
||||
if nil != key {
|
||||
optionSort := map[string]int{}
|
||||
|
|
|
@ -213,13 +213,17 @@ func (table *Table) SortRows(attrView *AttributeView) {
|
|||
sorted := true
|
||||
for _, colIndexSort := range colIndexSorts {
|
||||
val1 := editedRows[i].Cells[colIndexSort.Index].Value
|
||||
if nil == val1 {
|
||||
return colIndexSort.Order == SortOrderAsc
|
||||
}
|
||||
|
||||
val2 := editedRows[j].Cells[colIndexSort.Index].Value
|
||||
if nil == val2 {
|
||||
return colIndexSort.Order != SortOrderAsc
|
||||
if nil == val1 || val1.IsEmpty() {
|
||||
if nil != val2 && !val2.IsEmpty() {
|
||||
return false
|
||||
}
|
||||
sorted = false
|
||||
continue
|
||||
} else {
|
||||
if nil == val2 || val2.IsEmpty() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
result := val1.Compare(val2, attrView)
|
||||
|
|
Loading…
Add table
Reference in a new issue