How to create dynamic columns for Handsontable?

匿名 (未验证) 提交于 2019-12-03 01:47:02

问题:

I'm working with Handsontable to create a web grid that can copy / paste between web and excel, I tried with code below and it works fine:

  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,   }); 

Now I need create web grid with dynamic columns, I tried replace the column list with function below, but it does not works:

    columns:         function () {             var cols = [];             for (var i = 0; i 

Is it possible to create dynamic columns in Handsontable grid? and how to do it?

I'm a JavaScript beginner, so please tell me if there is any error I made, thanks!

回答1:

Resolved this problem by myself, function can not be used in column definition directly, but variable is allowed, so code below works:

var dynamicColumns = []; for (var i = 0; i 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!