Thread Rating:
  • 554 Vote(s) - 2.76 Average
  • 1
  • 2
  • 3
  • 4
  • 5
レコードの挿入で一番上の行が選択されてしまう
05-27-2013, 07:32 PM,
#3
RE: レコードの挿入で一番上の行が選択されてしまう
ヘルプを見ると、 「既存のインデックスおよび選択したものを保存する」とありますね。

私の望む振る舞いをしてくれました。

ありがとうございます。



Code:
{curl 8.0 applet}
{curl-file-attributes character-encoding = "utf8"}
{applet manifest = "manifest.mcurl",
    {compiler-directives careful? = true}
}
{let people:RecordSet =
    {RecordSet
        {RecordFields
            {RecordField "index", caption = "No.", domain = int},
            {RecordField "First", domain = String},
            {RecordField "Last", domain = String},
            {RecordField "Age", domain = int}
        }
    }
}

{for i:int = 0 to 10 do
    {people.append {RecordData index = i + 1, Age = i + 1}}
}
{define-class public SortrderGrid {inherits RecordGrid}
  {constructor public {default
                          record-source:#RecordSet = null,
                          ...}
    {construct-super {splice ...}}
    set self.record-source = record-source
  }
  ||グリッドのヘッダークリックでソートしたときには
  ||RecordSet からはこのイベントは発生しないため、
  ||継承したグリッドの sort セッターで無理やり発生させている
  {setter public {sort sort:#RecordSort}:void
    {if-non-null rs = self.record-source then
        {rs.handle-event {RecordsReordered}}
    }
    set super.sort = sort
  }
  {setter public {record-source rs:#RecordSet}:void
    set super.record-source = rs

    {if-non-null rs = self.record-source then
        {rs.add-event-handler
            {on e:RecordsChanged  at rs:RecordSet  do
                {type-switch e
                 case ra:RecordAdded do
                    def insert-index =  self.current-index + 1
                    {with rs.batch-events? = true do
                        {for idx:int = rs.size above 0  do
                            {if insert-index <= idx then
                                {if-non-null select-record =
                                    {rs.select-one
                                        filter = {RecordFilter
                                                     {proc {r:Record}:bool
                                                         {if r["index"] asa int == idx then
                                                             {return true}
                                                          else
                                                             {return false}
                                                         }
                                                     }
                                                 }
                                    } then
                                    set select-record["index"] = idx + 1
                                }
                            }
                        }
                        set ra.record["index"] = insert-index
                        {if-non-null sort = self.sort then
                            set super.sort = {RecordSort.concat sort, {RecordSort.from-string "index"}}
                        }
                    }
                    {return}
                 case ra:RecordModified do
                 case rr:RecordRemoved do
                 case ro:RecordsReordered do
                 case rbc:RecordsBulkChanges do
                 else
                    {return}
                }
                {after 0s do
                    {with
                        self.records.batch-events? = true ,
                        rs.batch-events? = true do
                        {for r key idx:int in self.records do
                            set r["index"] = idx + 1
                        }
                    }
                }
                {return}
            }
        }

        {rs.handle-event {RecordsReordered }}
    }
  }
}

{def grid =
    {SortrderGrid
        ||レコードの選択行が移動してしまう問題の対応
        key-spec = RecordSetDisplay.preserve-indices,
        record-source = people,
        height = 5in,
        width = 5in
    }
}
{CommandButton
    label = "挿入",
    {on Action do
        {if-non-null rs = grid.record-source then
            {rs.append {RecordData}}
        }
    }
}
{CommandButton
    label = "削除",
    {on Action do
        {if-non-null r = grid.current-record then
            {r.delete}
        }
    }
}
{value grid}


Messages In This Thread
RE: レコードの挿入で一番上の行が選択されてしまう - by umemura - 05-27-2013, 07:32 PM
Forum Jump:


Users browsing this thread:
3 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('902')