2016-05-23 14 views

Antwort

0

Hier ist ein Beispiel dafür, wie z.B. um eine vollständige Zeile basierend auf einem in einer bestimmten Spalte angegebenen Wert zu färben. Mit instance.getData() rufen Sie die vollständigen Daten im rhandsontable-Objekt ab. Sie können mithilfe der Indizierung auf bestimmte Zellen zugreifen.

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) 
Verwandte Themen