I have multiple table use-case where I am creating multiple tables on the same page dynamically. And I on button click I am adding Column but it’s updating other table data as well.
`
//Get the instance of HTML element
let tableContainerFirst = document.getElementById(“CreateOrderTableFirst”);
let tableContainerSecond = document.getElementById(“CreateOrderTableSecond”);
for( var index=0; index < 5; index++ ) {
if (index === 0 ) generateTable(arrayOfObjects, tableContainerFirst, index); //Call the function for table
if (index === 1 ) generateTable(arrayOfObjects_second, tableContainerSecond, index); //Call the function for table
generateTable(rawData, table_instance , table_index ) {
var hot_instance = new Handsontable(table_instance, {
language: languageCode || "en-US",
licenseKey: "non-commercial-and-evaluation",
//row headers without numbering
rowHeaders: false,
toggleAllCollapsibleSections: false,
data: rawData,
columns: headerConfig,
rowHeaderWidth: 50,
startCols: 0,
startRows: 0,
//Set readonly true to all cell
readOnly: true,
allowEmpty: true,
//Warping
wordWrap: true,
autoWrapCol: true,
contextMenu: true,
columnSorting: false,
allowInsertRow: true,
rowHeights: 25,
filters: false,
allowInsertColumn: true,
cells: function(row, column, prop) {
//Nested row CSS
var cellProperties = {className: 'htMiddle'};
return cellProperties;
},
nestedRows: true,
hiddenColumns: {},
mergeCells: []
});
let all_row_data = hot_instance.getData();
//Set dynamic mergeCell for table
let mergeCells = [{row: (all_row_data.length - 3), col: 0, colspan: 6, rowspan:3}];
hot_instance.getSettings().mergeCells = mergeCells;
hot_instance.updateSettings(hot_instance.getSettings().mergeCells);
//Save handsontable instace for every table
if ( table_index == 0 ) windows.hotInstance_1 = hot_instance;
if ( table_index == 1 ) windows.hotInstance_2 = hot_instance;
}
addColumn : function( component, event, helper ) {
console.log( event.currentTarget.value )
//Get the handsonTable settings with columns
let columnsArray = windows.hotInstance_1.getSettings().columns;
//Header index
let index = columnsArray.length;
//Allow only 5 order
if ( (index - 8) <= 5 ) {
let add_list = new Array(index - 8); // create an empty array with length of order
//Update the variable for view
//Create the Static Column with header and data
var item = {title: ( "Order " + (index - 8) ), data: ( "Order_" + (index - 8) ), className: "htRight", width: 80}
//Add cloumn on specifice index
columnsArray.splice(index - 2, 0, item);
//Set the Column on handsonTable
windows.hotInstance_1.getSettings().columns = columnsArray;
//Update the settings
windows.hotInstance_1.updateSettings(windows.hotInstance_1.getSettings());
}
}`