Post Reply 
 
Thread Rating:
  • 115 Votes - 2.78 Average
  • 1
  • 2
  • 3
  • 4
  • 5
レコードグリッドの行番号を表示するには?
08-20-2013, 04:14 PM (This post was last modified: 08-20-2013 05:22 PM by umemura.)
Post: #1
レコードグリッドの行番号を表示するには?
レコードグリッドに行番号を表示したいです。

よい実装方法はありますでしょうか。
Find all posts by this user
Quote this message in a reply
08-20-2013, 04:20 PM
Post: #2
RE: レコードグリッドの行番号
RecordGrid.row-background-spec を利用する方法があると思いますが、
そもそも行番号のためのプロパティではないですし、
並び替えのたびに、すべてのレコードが編集されてしまうのがうれしくありません。

中のレコードとは関係なく行番号を表示することはできないのでしょうか。

Code:
{define-proc public {notified rg:RecordGrid, r:Record, i:int}:#Background
    set r["id"] = {String i + 1}
    {return null}
}

{let people:RecordSet =
    {RecordSet
        {RecordFields
            {RecordField "id", domain = String},
            {RecordField "First", domain = String},
            {RecordField "Last", domain = String},
            {RecordField "Age", domain = int}
        },
        {RecordData id = "1", First = "John", Last = "Smith", Age = 25},
        {RecordData id = "1", First = "Jane", Last = "Smith", Age = 29},
        {RecordData id = "1", First = "Jane", Last = "Jones", Age = 28}
    }
}
{def rg =
    {RecordGrid
        row-background-spec = notified,
        record-source = people,
        height = 5cm,
        width = 8in,
        vertical-grid-line-width = 4px
    }
}

{value
    {VBox
        rg,
        {HBox
            {CommandButton
                width = {make-elastic}, label = "append record",
                {on Action do
                    {people.append {RecordData}}
                }
            },
            {CommandButton
                width = {make-elastic}, label = "delete current record",
                {on Action do
                    {if-non-null r = rg.current-record then
                        {r.delete}
                    }
                }
            },
            {CommandButton
                width = {make-elastic}, label = "commit records",
                bound-command = {rg.get-command "commit"}
            },
            {CommandButton
                width = {make-elastic}, label = "revert records",
                bound-command = {rg.get-command "revert"}
            }
        }
    }
}
Find all posts by this user
Quote this message in a reply
08-21-2013, 08:36 AM (This post was last modified: 08-21-2013 08:54 AM by Yuhki.)
Post: #3
RE: レコードグリッドの行番号
RecordGridColumnのformat-specを利用してはどうでしょうか?

Code:
{RecordGridColumn
"id",
format-spec =
    {proc {data:any, r:Record}:String
        {return {String {rg.records.get-index r} + 1}}
    }
}

ただ、処理の負荷を考えるとRecordGridCellを継承したクラスを作って
formatメソッドにてRecordGridCell.record-indexを返すようにするほうが
いいかもしれませんね。
Find all posts by this user
Quote this message in a reply
08-21-2013, 01:31 PM
Post: #4
RE: レコードグリッドの行番号を表示するには?
RecordGridCell.record-index ですか!

format-spec を使うと、対象のRecordSetに存在する RecordField.field-name を指定しないと表示できない?のですかね?
対象のレコードに依存せずに、カラム単体で行番号を表示できるようにしたいです。
とりあえず、 refresh-data を利用してみました。

Code:
{define-class public LineNumberCell {inherits RecordGridCell }
  field line-number-frame:Frame = {Frame halign = "right", margin = 1pt}
  {constructor public {default ...}
    {construct-super {splice ...}}
    {self.add-internal self.line-number-frame}
  }
  {method public {refresh-data }:void
    {self.line-number-frame.add replace? = true, self.record-index + 1}
  }
}

{define-class public LineNumberColumnl {inherits RecordGridColumn}
  {constructor public {default
                          width:any = 20pt,
                          header-spec:any = "No.",
                          ...}
    {construct-super
        "",
        header-spec = header-spec,
        width = width,
        {splice ...}}
    set self.cell-spec = LineNumberCell
    set self.editable? = false
  }
}


{let people:RecordSet =
    {RecordSet
        {RecordFields
            {RecordField "First", domain = String},
            {RecordField "Last", domain = String},
            {RecordField "Age", domain = int}
        },
        {RecordData First = "John", Last = "Smith", Age = 25},
        {RecordData First = "Jane", Last = "Smith", Age = 29},
        {RecordData First = "Jane", Last = "Jones", Age = 28}
    }
}
{def rg =
    {RecordGrid
        {LineNumberColumnl},
        record-source = people,
        height = 5cm,
        width = 8in,
        vertical-grid-line-width = 4px
    }
}
{value rg}
Find all posts by this user
Quote this message in a reply
08-21-2013, 05:57 PM
Post: #5
RE: レコードグリッドの行番号を表示するには?
umemuraさんのコードを試させていただきましたが、なかなかよい感じですね。

個人的には行選択した場合に行番号セルも選択色になって欲しい気がするので、
RecordGridCell のかわりに StandardStringCell を継承するのはどうでしょうか?

Code:
{define-class public LineNumberCell {inherits StandardStringCell}
  field line-number-frame:Frame = {Frame halign = "right", margin = 1pt}
  {constructor public {default ...}
    {construct-super {splice ...}}
    set self.cells-take-focus? = false
  }
  {method public {refresh-data }:void
    {super.refresh-data}
    set self.display-graphic.contents = {String (self.record-index + 1)}
  }
}
Find all posts by this user
Quote this message in a reply
Post Reply 

Forum Jump:


User(s) browsing this thread:
1 Guest(s)