カスタムレンダラー関数を使用して、Handsontableの特定のセルにスタイルを適用したいとします。 if条件を使用してスタイルを適用する必要があります。ここで、handsontable内の別のセルの値を確認する必要があります。Handsontableの別のセルの条件/値に基づいてセルにスタイルを適用する方法
カスタムレンダラを使用してこれを達成する方法はありますか?
カスタムレンダラー関数を使用して、Handsontableの特定のセルにスタイルを適用したいとします。 if条件を使用してスタイルを適用する必要があります。ここで、handsontable内の別のセルの値を確認する必要があります。Handsontableの別のセルの条件/値に基づいてセルにスタイルを適用する方法
カスタムレンダラを使用してこれを達成する方法はありますか?
ドキュメントに条件付き書式設定を実装する方法については、great demoがあります。
特定の列に指定された値に基づいて完全な行を色付けします。 instance.getData()
を使うと、rhandsontableオブジェクトの完全なデータを取得できます。インデックス作成を使用して特定のセルにアクセスできます。
library(rhandsontable)
DF = data.frame(bool = TRUE,val = 1:10, big = LETTERS[1:10],
small = letters[1:10],
stringsAsFactors = FALSE)
text_renderer <- "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
var col_value = instance.getData()[row][2]
if (col_value == 'C') {
td.style.background = 'pink';
} else if (col_value == 'D') {
td.style.background = 'green';
}
}"
bool_renderer <- "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.CheckboxRenderer.apply(this, arguments);
var col_value = instance.getData()[row][2]
if (col_value == 'C') {
td.style.background = 'pink';
} else if (col_value == 'D') {
td.style.background = 'green';
}
}
"
rhandsontable(DF, readOnly = FALSE, width = 750, height = 300) %>%
hot_col(col = c(2, 3, 4), renderer = text_renderer) %>%
hot_col("bool", renderer = bool_renderer)