🎨 Database table view supports paged loading https://github.com/siyuan-note/siyuan/issues/9424
This commit is contained in:
parent
535f72afdb
commit
79960b4da2
3 changed files with 45 additions and 11 deletions
|
@ -28,10 +28,11 @@ type LayoutTable struct {
|
|||
Spec int `json:"spec"` // 布局格式版本
|
||||
ID string `json:"id"` // 布局 ID
|
||||
|
||||
Columns []*ViewTableColumn `json:"columns"` // 表格列
|
||||
RowIDs []string `json:"rowIds"` // 行 ID,用于自定义排序
|
||||
Filters []*ViewFilter `json:"filters"` // 过滤规则
|
||||
Sorts []*ViewSort `json:"sorts"` // 排序规则
|
||||
Columns []*ViewTableColumn `json:"columns"` // 表格列
|
||||
RowIDs []string `json:"rowIds"` // 行 ID,用于自定义排序
|
||||
Filters []*ViewFilter `json:"filters"` // 过滤规则
|
||||
Sorts []*ViewSort `json:"sorts"` // 排序规则
|
||||
PageSize int `json:"pageSize"` // 每页行数
|
||||
}
|
||||
|
||||
type ViewTableColumn struct {
|
||||
|
@ -571,13 +572,14 @@ func (value *Value) CompareOperator(other *Value, operator FilterOperator) bool
|
|||
|
||||
// Table 描述了表格实例的结构。
|
||||
type Table struct {
|
||||
ID string `json:"id"` // 表格布局 ID
|
||||
Icon string `json:"icon"` // 表格图标
|
||||
Name string `json:"name"` // 表格名称
|
||||
Filters []*ViewFilter `json:"filters"` // 过滤规则
|
||||
Sorts []*ViewSort `json:"sorts"` // 排序规则
|
||||
Columns []*TableColumn `json:"columns"` // 表格列
|
||||
Rows []*TableRow `json:"rows"` // 表格行
|
||||
ID string `json:"id"` // 表格布局 ID
|
||||
Icon string `json:"icon"` // 表格图标
|
||||
Name string `json:"name"` // 表格名称
|
||||
Filters []*ViewFilter `json:"filters"` // 过滤规则
|
||||
Sorts []*ViewSort `json:"sorts"` // 排序规则
|
||||
Columns []*TableColumn `json:"columns"` // 表格列
|
||||
Rows []*TableRow `json:"rows"` // 表格行
|
||||
RowCount int `json:"rowCount"` // 表格总行数
|
||||
}
|
||||
|
||||
type TableColumn struct {
|
||||
|
|
|
@ -622,6 +622,8 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View, page, p
|
|||
return iv < jv
|
||||
})
|
||||
|
||||
// 分页
|
||||
ret.RowCount = len(ret.Rows)
|
||||
if 0 < pageSize {
|
||||
start := (page - 1) * pageSize
|
||||
end := start + pageSize
|
||||
|
@ -959,6 +961,34 @@ func setAttributeViewSorts(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewPageSize(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewPageSize(operation)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func setAttributeViewPageSize(operation *Operation) (err error) {
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetCurrentView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
view.Table.PageSize = int(operation.Data.(float64))
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewColCalc(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewColumnCalc(operation)
|
||||
if nil != err {
|
||||
|
|
|
@ -204,6 +204,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
ret = tx.doSetAttrViewFilters(op)
|
||||
case "setAttrViewSorts":
|
||||
ret = tx.doSetAttrViewSorts(op)
|
||||
case "setAttrViewPageSize":
|
||||
ret = tx.doSetAttrViewPageSize(op)
|
||||
case "setAttrViewColWidth":
|
||||
ret = tx.doSetAttrViewColumnWidth(op)
|
||||
case "setAttrViewColWrap":
|
||||
|
|
Loading…
Add table
Reference in a new issue