2013-07-03 62 views
0

我有一个包含2行3个日期的手表,并且我想在新的日期插入非空单元格时将颜色更改为绿色。Handsontable和单元格的颜色

我对handsontable功能

function startperspective() { 

    $.getJSON("/Reporting/getperspective", function(data) { 
     var reg = new RegExp('^((0[1-9]{1}|[12]{1}[0-9]{1}|3[01]{1})\/(0[1-9]{1}|1[012]{1})\/[0-9]{4}$)'); 
     if (data !== null) { 
      $("#old_tab_handsontable").handsontable({ 
       data: data, 
       colHeaders: ['Date Perspective', 'Date Archive', 'Date des valeurs finales'], 
       columns: [ 
        {data: 'datePers', type: 'date', dateFormat: 'dd/mm/yy'}, 
        {data: 'dateArchive', type: 'date', dateFormat: 'dd/mm/yy'}, 
        {data: 'dateDef', type: 'date', dateFormat: 'dd/mm/yy'} 
       ], 
       colWidths: [200, 200, 200], 
       fillHandle: false, 
       onBeforeChange: function(data) { 
        for (var ind = data.length - 1; ind >= 0; ind--) { 
         if ((!reg.test(data[ind][3]))) { 
          data[ind][3] = data[ind][2]; 
          return false; 
         } 
         else { 
          if (data[ind][3] !== data[ind][2]) { 
           TabChange = true; 
           return true; 
          } 
         } 
        } 
       } 
      }); 
     } 
} 

TabChange是一个布尔值,以检查是否我有保存或不是一个新的细胞。我认为我需要在'onBeforeChange'中的某些东西从我的手表中删除,但我不知道是什么。

我想避免改变cellProperties,因为它会删除我的手表的datepicker。

+0

哪个版本? – PostureOfLearning

回答

1

如果我理解你是正确的,在发生变化之后,你想要比较前后值,如果它从一个日期改变到另一个日期,那么你想要将该单元格变为绿色。

如果是这样的话,那么我会用改动后

afterChange: function(changes, source){ 

    if (source=== 'loadData') { 
     return; //don't do anything as this is called when table is loaded 
    } 
    var rowIndex = changes[0]; 
    var col = changes[1]; 
    var oldCellValue = changes[2]; 
    var newCellValue = changes[3]; 

    //compare oldCellValue with newCellValue to ensure it is the change you are after 
    //you need to apply the logic you need but for example: 
    if(oldCellValue !== newCellValue){ 
     //Here you set the background color to green 
    } 
} 

你可能也想看看你用conditional formatting