1 Star 0 Fork 0

程序员锡哥/walk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
maptablemodel.go 1.52 KB
一键复制 编辑 原始数据 按行查看 历史
// Copyright 2013 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build windows
package walk
import (
"sort"
)
type mapTableModel struct {
TableModelBase
SorterBase
dataMembers []string
dataSource interface{}
items []map[string]interface{}
}
func newMapTableModel(dataSource interface{}) (TableModel, error) {
items, ok := dataSource.([]map[string]interface{})
if !ok {
return nil, newError("dataSource must be assignable to []map[string]interface{}")
}
return &mapTableModel{dataSource: dataSource, items: items}, nil
}
func (m *mapTableModel) setDataMembers(dataMembers []string) {
m.dataMembers = dataMembers
}
func (m *mapTableModel) RowCount() int {
return len(m.items)
}
func (m *mapTableModel) Value(row, col int) interface{} {
if m.items[row] == nil {
if populator, ok := m.dataSource.(Populator); ok {
if err := populator.Populate(row); err != nil {
return err
}
}
if m.items[row] == nil {
return nil
}
}
return m.items[row][m.dataMembers[col]]
}
func (m *mapTableModel) Sort(col int, order SortOrder) error {
m.col, m.order = col, order
sort.Stable(m)
m.changedPublisher.Publish()
return nil
}
func (m *mapTableModel) Len() int {
return m.RowCount()
}
func (m *mapTableModel) Less(i, j int) bool {
col := m.SortedColumn()
return less(m.Value(i, col), m.Value(j, col), m.SortOrder())
}
func (m *mapTableModel) Swap(i, j int) {
m.items[i], m.items[j] = m.items[j], m.items[i]
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/msgy/walk.git
git@gitee.com:msgy/walk.git
msgy
walk
walk
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385