RecordGridの自動計算

【ご質問】
RecordGridにて値を入力して別のセルにカーソルが移動したときに
累積値を再計算して表示することは可能でしょうか?

【回答】
カスタムセルを使用し、”note-grid-focus-out”メソッド内で
計算を行うロジックを呼び出すことで実現可能です。

詳細は以下のサンプルをご参照ください。

{curl 6.0,7.0,8.0 applet}
{curl-file-attributes character-encoding = “shift-jis”}

{let price:RecordSet =
    {RecordSet
        {RecordFields
            {RecordField
                “value”, domain = float
            },
            {RecordField
                “number”, domain = float
            },
            {RecordField
                “price”, domain = float
            }
        },
        {RecordData value = 1000, number = 2, price = 2000},
        {RecordData value = 1000, number = 3, price = 3000},
        {RecordData value = 1000, number = 4, price = 4000}
    }
}

{let rg:RecordGrid =
    {RecordGrid
        height = 5cm,
        width = 9.75cm,
        record-source = price,
        {RecordGridColumn “value”, editable? = true, cell-spec = ControlCell},
        {RecordGridColumn “number”, editable? = true, cell-spec = ControlCell},
        {RecordGridColumn “price”, editable? = false, cell-spec = ControlCell}
    }
}

{define-proc public {calc index:int}:void
    let r:#Record = rg.records[index]
    let value:float = r[“value”]
    let number:float = r[“number”]
    set r[“price”] = value * number
}

{define-class public ControlCell {inherits StandardStringCell}

  field index:int

  {constructor public {default}
    {construct-super}
    set self.index = 0
  }

  {method public {note-grid-focus-in}:void
    {super.note-grid-focus-in}
    set self.index = rg.current-index
  }

  {method public {note-grid-focus-out}:void
    {super.note-grid-focus-out}
    {calc self.index}
  }
}

{value
    {VBox
        rg
    }
}