Not able to initialize Handsontable inside a UI dialog modal

Tags: #<Tag:0x00007efc6b162330>

Hi I have tried Initializing handsontable inside UI Dialog modal popup. It gives me below errors -

handsontable.full.min.js:26 Uncaught TypeError: t._arrayMap.splice is not a function
at handsontable.full.min.js:26
at o (handsontable.full.min.js:26)
at e.insertItems (handsontable.full.min.js:26)
at t.value (handsontable.full.min.js:38)
at t.value (handsontable.full.min.js:38)
at i. (handsontable.full.min.js:26)
at e.value (handsontable.full.min.js:26)
at i.runHooks (handsontable.full.min.js:33)
at t.value (handsontable.full.min.js:26)
at i. (handsontable.full.min.js:26)
(anonymous) @ handsontable.full.min.js:26
o @ handsontable.full.min.js:26
insertItems @ handsontable.full.min.js:26
value @ handsontable.full.min.js:38
value @ handsontable.full.min.js:38
(anonymous) @ handsontable.full.min.js:26
value @ handsontable.full.min.js:26
runHooks @ handsontable.full.min.js:33
value @ handsontable.full.min.js:26
(anonymous) @ handsontable.full.min.js:26
value @ handsontable.full.min.js:26
runHooks @ handsontable.full.min.js:33
init @ handsontable.full.min.js:33
i @ handsontable.full.min.js:33
open @ detail_2_5.js:406
_trigger @ jquery-ui-1.12.1.min.js:6
open @ jquery-ui-1.12.1.min.js:11
(anonymous) @ jquery-ui-1.12.1.min.js:6
_init @ jquery-ui-1.12.1.min.js:11
(anonymous) @ jquery-ui-1.12.1.min.js:6
_createWidget @ jquery-ui-1.12.1.min.js:6
t.(anonymous function).(anonymous function) @ jquery-ui-1.12.1.min.js:6
(anonymous) @ jquery-ui-1.12.1.min.js:6
each @ jquery-1.11.0.js:384
each @ jquery-1.11.0.js:137
t.fn.(anonymous function) @ jquery-ui-1.12.1.min.js:6
model @ detail_2_5.js:378
success @ detail_2_5.js:326
fire @ jquery-1.11.0.js:3099
fireWith @ jquery-1.11.0.js:3211
done @ jquery-1.11.0.js:9310
callback @ jquery-1.11.0.js:9720
XMLHttpRequest.send (async)
send @ jquery-1.11.0.js:9666
ajax @ jquery-1.11.0.js:9211
importEDRXMLData @ detail_2_5.js:316
onclick @ simplifiedReport.php?SiteType=PhaseI&SiteID=14&PID=474971&Stage=Write&Tab=contenttoc&SectionID=41:1445
60handsontable.full.min.js:26 Uncaught TypeError: Cannot read property ‘offsetLeft’ of undefined
at C (handsontable.full.min.js:26)
at t.value (handsontable.full.min.js:38)
at t.value (handsontable.full.min.js:38)
at HTMLHtmlElement. (handsontable.full.min.js:38)
at HTMLHtmlElement.r (handsontable.full.min.js:26)

In normal cases its working fine. Can you please help me out finding the reason for this issue.

Thank you!!

Can you share a demo where this issue can be replicable?

hi, Thank you for the quick reply, here is my code that is creating a dialog

		var header ='<th style="width:100px;border:1px solid black;"><input type="checkbox" class="selectAllRows" /></th>';
		var body = "";
		for(var index in data) {
			var rowData = data[index];
			for( var key in rowData) {
				header = header + '<th style="width:250px;border:1px solid black;">' + key + '</th>';
			}
			break;
		}
		for(var index in data) {
			var rowData = data[index];
			body = body + '<tr style="border:1px solid black;text-align:center;"><td><input type="checkbox" class="rowSelect" /></td>';
			for( var key in rowData) {
				body = body + '<td style="border:1px solid black;">' + rowData[key] + '</td>';
			}
			body = body + '</tr>';
		}

		//'<script type="text/javascript" language="javascript" src="/js/Handsontable5/handsontable.full.min.js"></script>'
		 //'<link rel="stylesheet" type="text/css" href="/js/Handsontable5/handsontable.full.min.css" />'
			
		var dialogTemplate = '<div id="dialog-2" style="width:950px;height:500px;">' +
								'<br>' +
								'<div>' +
									'Please Select No. of years &nbsp;<select id="userInput">' +
								    '<option value="10">Last 10 Years</option>' +
								    '<option value="20">Last 20 Years</option>' +
								    '<option value="25">Last 25 Years</option>' +
								    '<option value="30">Last 30 Years</option>' +
								    '<option value="ALL" selected="selected">All Records</option>' +
								'</select>' +
								'</div>' +
								'<br>' +
								'<br>' +
								'<div id="container" class="handsontable"></div>' +
								'<div>' +
									'<table id="detailTableData" style="width:650px;border:1px solid black;">' +
										'<tr style="border:1px solid black;">' + header +'</tr>' + body
									'</table>' +
								'</div>' +
							'</div>';
		
		jQuery(dialogTemplate).dialog({
	        modal: true,
	        draggable: false,
	        resizable: true,
	        maxWidth: "1000px",
	        height: "500px",
	        width: "950px",
	        title: "Import",
			hideCloseButton: false,
			open: function() {
				jQuery(".ui-dialog").css({"left":"100px","top":"5px","margin-top": "70px", "margin-left":"105px", "width": "950px", "height": "500px","z-index":"9999"});
				jQuery("#dialog-2").css({"display": "block","width": "auto","min-height": "350px","max-height": "450px","height": "400px"});
				jQuery(".ui-dialog-titlebar").css({"float": "right !important","margin-top":"12px !important","margin-right":"10px !important","height":"15px !important","color":"#ffffff !important","background": "#3074a6 !important","border":"1px solid #3074a6 !important","height":"40px","border":".1em solid #eeeeee","border-bottom-right-radius": "0px","border-bottom-left-radius": "0px","border-top-right-radius": "0px","border-top-left-radius": "0px", "padding-top": "0px", "padding-right": "0px","padding-left": "0px"});
				jQuery(".ui-corner-all").css({"border-bottom-right-radius": "0px","border-bottom-left-radius": "0px","border-top-right-radius": "0px","border-top-left-radius": "0px", "padding-top": "0px", "padding-right": "0px","padding-left": "0px"});
				jQuery(".ui-dialog-title").css({"margin-top": "10px","margin-left": "10px","color": "#ffffff","float": "left","line-height": "25px","font-style": "normal","font-family": "Arial","font-weight": "700","font-size": "18px"});
				jQuery(".ui-widget-header").css({"border": "1px solid #3074a6", "background": "#3074a6 url(/images/ui-bg_gloss-wave_35_f6a828_500x100.png)50% 50% repeat-x"});
				jQuery(".dialog-button").css({"height":"35px","width":"70px","margin-top":"3px","margin-right":"10px","font-family":"Arial","font-size":"13px","color":"#3074a6","float":"right","background":"#ffffff"});
				jQuery(".dialog-import").css({"height":"35px","width":"100px","margin-top":"3px","margin-right":"20px","font-family":"Arial","font-size":"13px","color":"#ffffff","float":"right","background":"#3074a6"});
				jQuery(".ui-widget").css({"font-family": "Arial","font-size": "13px","background": "#ffffff"});
				jQuery(".ui-widget-content").css({"border-": "1px solid #dddddd","background": "#ffffff url(/images/ui-bg_highlight-soft_100_eeeeee_1x100.png) 50% top repeat-x"});
				
				var hotdata = [
					  ["", "Ford", "Tesla", "Toyota", "Honda"],
					  ["2017", 10, 11, 12, 13],
					  ["2018", 20, 11, 14, 13],
					  ["2019", 30, 15, 12, 13]
					];
				
				var hot = new Handsontable(jQuery("#container"), {
					  data: hotdata,
					  minSpareRows: 1,
				      rowHeaders: true,
				      colHeaders: true,
				      contextMenu: true
				});
				hot.render();
								
				jQuery("#userInput").on("change", function() {
					var selectedYear = jQuery("#userInput option:selected").val();
					if(selectedYear === "ALL") {
						jQuery('#detailTableData tbody').replaceWith('<tbody><tr style="border:1px solid black;">' + header +'</tr>' + body + '</tbody>');
					} else {
						var updateBody="";
						for(var index in actualData) {
							var rowData = actualData[index];
							if(rowData["CDDate"] && (rowData["CDDate"] >= ((new Date()).getFullYear() - selectedYear))) {
								updateBody = updateBody + '<tr style="border:1px solid black;text-align:center;"><td><input type="checkbox" class="rowSelect" /></td>';
								for( var key in rowData) {
									updateBody = updateBody + '<td style="border:1px solid black;">' + rowData[key] + '</td>';
								}
								updateBody = updateBody + '</tr>';
							} 
							if(rowData['AerialDate'] && (rowData["AerialDate"] >= ((new Date()).getFullYear() - selectedYear))) {
								updateBody = updateBody + '<tr style="border:1px solid black;text-align:center;"><td><input type="checkbox" class="rowSelect" /></td>';
								for( var key in rowData) {
									updateBody = updateBody + '<td style="border:1px solid black;">' + rowData[key] + '</td>';
								}
								updateBody = updateBody + '</tr>';
							}
						}
						jQuery('#detailTableData tbody').replaceWith('<tbody><tr style="border:1px solid black;">' + header +'</tr>' + updateBody + '</tbody>');
					}
				});
			},
			buttons: [
				{
					text: "Import",
					"class" : "dialog-import",
					click: function() {
						jQuery(this).dialog('destroy').remove();
						jQuery(".modal-backdrop").remove();
					}
				},
				{
					text: "Append",
					"class" : "dialog-button",
					click: function() {
						jQuery(this).dialog('destroy').remove();
						jQuery(".modal-backdrop").remove();
					}
				},
				{
					text: "Cancel",
					"class" : "dialog-button",
					click: function() {
						jQuery(this).dialog('destroy').remove();
						jQuery(".modal-backdrop").remove();
					}	
				}
			]
		});

The div is initialized before HOT, I have tried adding HOT code inside my on change function also.

The demo is Quite difficult for me as i am adding code to existing code of my project

Hey, this works for me now. Looks like its a stupid solution but it worked. What I have done is initialized HOT table without data and then updated the instance with the data.

Thank you!!

I am so happy that it works fine. I guess that we can close the ticket.