0

空でないセルに新しい日付が挿入されたときに、緑の色を変更したいと考えています。

ハンドソンテーブルの私の機能は

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 を変更することは避けたいと思います。

4

1 に答える 1

1

変更があった後、変更前と変更後の値を比較し、ある日付から別の日付に変更された場合は、そのセルを緑色にします。

この場合、afterChange を使用します。

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
    }
}

条件付き書式もご覧ください

于 2013-07-05T00:55:47.673 に答える