2013-11-14 79 views
0

如何將默認值設置爲僅針對Handson表中的新行進行檢查?如何將默認值添加到Handson表格中的複選框?

在以下鏈接中,如何設置列「C」checked = true僅作爲新行的默認值。

有什麼想法?

http://handsontable.com/demo/renderers.html

$(document).ready(function() { 

    var data = [ 
    {id: 1, name: "Ted", isActive: true, color: "orange", date: "2008-01-01"}, 
    {id: 2, name: "John", isActive: false, color: "black", date: null}, 
    {id: 3, name: "Al", isActive: true, color: "red", date: null}, 
    {id: 4, name: "Ben", isActive: false, color: "blue", date: null} 
    ]; 

    var yellowRenderer = function (instance, td, row, col, prop, value, cellProperties) { 
    Handsontable.TextCell.renderer.apply(this, arguments); 
    $(td).css({ 
     background: 'yellow' 
    }); 
    }; 

    var greenRenderer = function (instance, td, row, col, prop, value, cellProperties) { 
    Handsontable.TextCell.renderer.apply(this, arguments); 
    $(td).css({ 
     background: 'green' 
    }); 
    }; 

    var $container = $("#example1"); 
    $container.handsontable({ 
    data: data, 
    startRows: 5, 
    colHeaders: true, 
    minSpareRows: 1, 
    columns: [ 
     {data: "id", type: 'text'}, 
     //'text' is default, you don't actually have to declare it 
     {data: "name", type: {renderer: yellowRenderer}}, 
     {data: "isActive", type: 'checkbox'}, 
     {data: "date", type: 'date'}, 
     {data: "color", 
     type: 'autocomplete', 
     source: ["yellow", "red", "orange", "green", "blue", "gray", "black", "white"] 
     } 
    ], 
    cells: function (row, col, prop) { 
     if (row === 0 && col === 0) { 
     this.renderer = greenRenderer; 
     } 
    } 
    }); 

    function bindDumpButton() { 
     $('body').on('click', 'button[name=dump]', function() { 
     var dump = $(this).data('dump'); 
     var $container = $(dump); 
     console.log('data of ' + dump, $container.handsontable('getData')); 
     }); 
    } 
    bindDumpButton(); 

}); 
+0

新增的jsfiddle例如 – Think

+0

小提琴是空白 – tymeJV

+0

這是Handsontable例如http://handsontable.com/demo/renderers.html – Think

回答

1

我能夠通過添加一些代碼來afterCreateRow回調弄清楚自己

我們可以爲新創建的行設置缺省列值。我沒有添加下面的代碼到afterCreateRow回調似乎工作正常。

afterCreateRow: function(index) { 
         if (handsontable != undefined) { 
          var data = $("#hsTable").data('handsontable').getData(); 
          data[index - 1].(dataSchemaField)= true; 
         } 
        } 
相關問題