2013-07-03 64 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