Как добавить значение по умолчанию для флажка в таблице Handson?

0

Как установить значение по умолчанию, которое указано только для новой строки в таблице 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
  • 0
    Скрипка пуста
Показать ещё 1 комментарий
Теги:
handsontable

1 ответ

1

Я смог выяснить себя

Мы можем установить значения столбцов по умолчанию для вновь созданной строки, добавив некоторый код в обратные вызовы afterCreateRow. Я добавил следующий код для обратного вызова afterCreateRow, похоже, работает нормально.

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

Ещё вопросы

Сообщество Overcoder
Наверх
Меню