4

Handsontable を使用して、Web と Excel 間でコピー/貼り付けできる Web グリッドを作成しています。以下のコードを試してみましたが、正常に動作します。

  var first = true;
  var exampleGrid = $("#exampleGrid");
  exampleGrid.handsontable({
      rowHeaders: true,
      colHeaders: true,
      stretchH: 'all',
      minSpareCols: 0,
      minSpareRows: 0,
      height: 600,
      columns: [
      { data: "Id", title: "ID", type: "text" }, //'text' is default, you don't actually have to declare it
      { data: "Name", title: "Name", type: "text" },
      { data: "DisplayColor",
      title: "Display Color",
      type: 'autocomplete',
      source: ["yellow", "red", "orange", "green", "blue", "gray", "black", "white"]
      },
      { data: "Description", title: "Description", type: 'text' },
      { data: "IsDeleted", title: "Is Deleted", type: 'checkbox' }
      ],
      colWidths: [400, 100, 60, 100, 50, 40, 40, 60], //can also be a number or a function
      contextMenu: false,
  });

ここで、動的列を使用して Web グリッドを作成する必要があります。列リストを以下の関数に置き換えようとしましたが、機能しません。

    columns:
        function () {
            var cols = [];
            for (var i = 0; i < 1; i++) {
                var col = new Object();

                col.data = "Name";
                col.title = "Name" + i.toString();
                col.type = "text";
                cols[i] = col;
            }
            return cols;
        },

Handsontable グリッドで動的列を作成することは可能ですか? そしてそれを行う方法は?

私はJavaScript初心者なので、何かエラーがあれば教えてください。よろしくお願いします。

4

1 に答える 1