addRow() problem

hi,

I’ve problem with addRow function, when I try add row there an error occur. and I’ve searching this forum but still can’t resolve the problem, here my code :

jQuery(document).bind('keydown', keyStroke+'+1',function (evt) { //F12

	var selectedId=mygrid.getSelectedRowId();

	var rowId=mygrid.getSelectedRowId();

	var rowIndex=mygrid.getRowIndex(rowId);

	var ind=mygrid.getSelectedCellIndex();

	var rowAttr = mygrid.getRowAttribute(rowId,"class");

	var parentId = mygrid.getRowAttribute(rowId,"title");

	

	if(selectedId==undefined || selectedId==null) selectedId='node-0';		

	if(rowAttr==undefined || rowAttr==null) rowAttr=0;

	if(parentId==undefined || parentId==null) parentId='';

	//var n = rowId.split('-');

	var last_id=mygrid.getRowId(mygrid.getRowsNum()-1);

	var n = last_id.split('-');

	var nama_brg = mygrid.cells(rowId,3).getValue();

	var newId;

	if(nama_brg=="" && rowId != "node-0")

	{

		newId = n[0]+'-'+(parseFloat(n[1]));	

	}

	else

	{

		newId = n[0]+'-'+(parseFloat(n[1])+1);

	}

        mygrid.clearSelection();			

        mygrid.addRow(newId,"");

        mygrid.selectCell(mygrid.getRowsNum()-1,3,true,true);

        mygrid.editCell();

the error message is :
a is undefined
hxxp://192.168.0.19/devel2/sources/tera … id_form.js
Line 10

thanks you for your advanced, maybe usefull info I use firefox+firebug for debug and I use dhtmlxPro

Unfortunately we cannot reproduce this issue locally. Can you please provide complete demo where we can reproduce it?

hmm, sorry I don’t have. but I create small script for POC the problem. Unfortunately the error occur when I create grid from tables, for grid from xml the script is fine, no error occur. If I’m not mistake the error produce when I include “dhtmlxgrid_form.js” here the script.

<head>
<link rel="STYLESHEET" type="text/css" href="assets/dhtmlx/codebase/dhtmlxgrid.css">
<link rel="stylesheet" type="text/css" href="assets/dhtmlx/codebase/skins/dhtmlxgrid_dhx_skyblue.css">
<link rel="STYLESHEET" type="text/css" href="assets/dhtmlx/dhtmlxCombo/codebase/dhtmlxcombo.css">
<link rel="stylesheet" href="assets/scripts/jquery.autocomplete.css" type="text/css" />
<script src="assets/dhtmlx/codebase/dhtmlxcommon.js"></script>
<script src="assets/dhtmlx/dhtmlxCombo/codebase/dhtmlxcombo.js" type="text/javascript"></script>
<script src="assets/dhtmlx/codebase/dhtmlxgrid.js"></script>
<script src="assets/dhtmlx/codebase/dhtmlxgridcell.js"></script>
<script src="assets/dhtmlx/codebase/excells/dhtmlxgrid_excell_combo.js" type="text/javascript"></script>
<script src="assets/dhtmlx/codebase/ext/dhtmlxgrid_math.js" type="text/javascript"></script>
<script src="assets/dhtmlx/codebase/ext/dhtmlxgrid_filter.js" type="text/javascript"></script>
<script src="assets/dhtmlx/codebase/ext/dhtmlxgrid_validation.js"></script>
<script src="assets/dhtmlx/codebase/ext/dhtmlxgrid_start.js"></script>
<script src="assets/dhtmlx/codebase/ext/dhtmlxgrid_keymap_excel.js"></script>
<script src="assets/dhtmlx/codebase/ext/dhtmlxgrid_deprecated.js"></script>
<script src='assets/dhtmlx/codebase/ext/dhtmlxgrid_form.js'></script>
<script src="images/popup2.js"></script>
<script type="text/javascript" src="assets/scripts/lib/jquery.bgiframe.min.js"></script>
<script type="text/javascript" src="assets/scripts/jquery.autocomplete.min.js"></script>
<script>
	dhtmlx.skin = "dhx_skyblue";
	window.dhx_globalImgPath = "assets/dhtmlx/codebase/imgs/";
</script>
<body>
<table name="mygrid" class="dhtmlxGrid" height="180px" id="gridTransaksi" imgpath="assets/dhtmlx/codebase/imgs/" style="width:100%;" lightnavigation="true">
	<tr>		
		<td>No</td>
		<td>&nbsp;</td>
		<td width="75px">{dijamin}</td>
		<td width="300px">{Nama Obat}</td>
		<td width="50px">{Jml}</td>
		<td width="50px">{Satuan}</td>
		<td width="100px">{Harga Jual}</td>
		<td width="100px">{Tuslah}</td>
		<td width="100px">{Sub Total}</td>	    
		<td width="175px">{Signa}</td>
		<td width="425px">{Signa Tambahan}</td>
		<td width="175px">{Dosis}</td>
		<td width="250px">{Peringatan}</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
<tr id="node-1">										
					<td type="ro">1</td>
					<td type="ro"></td>
					<td type="ch" style="text-align:center"></td>
					<td>12NI-POL-POLYCROL FORTE SYR 100 ML 1S</td>
					<td type="ed">1</td>
					<td id="kdsatuan" type="ed">BOTOL</td>
					<td align="right" type="ro">14520</td>
					<td type="ro" align="right">100</td>
					<td align="right" type="math">=c4*c6+c7</td>
					<td type="coro"></td>
					<td type="coro">PC</td>
					<td type="coro"></td>
					<td type="coro"></td>										
					<td style="display:none;" type="ed">12NI-POL</td>
					<td style="display:none;" type="ed"></td>
					<td style="display:none;" type="ed">f</td>
					<td style="display:none;" type="ed">45</td>
					<td style="display:none;" type="ed">14520</td>
					<td style="display:none;" type="ed">{&quot;BOTOL&quot;:[&quot;1&quot;]}</td>
					<td style="display:none;" type="ed"></td>
					</tr>
	<tr id="node-2">										
					<td type="ro">2</td>
					<td type="ro"></td>
					<td type="ch" style="text-align:center"></td>
					<td>14-STESO-STESOLID INJ 10 MG/2 ML 5S</td>
					<td type="ed">0</td>
					<td id="kdsatuan" type="ed">AMP</td>
				<td align="right" type="ro">18000</td>
					<td type="ro" align="right">100</td>
					<td align="right" type="math">=c4*c6+c7</td>
					<td type="coro"></td>
					<td type="coro">PG</td>
				<td type="coro"></td>
					<td type="coro">00009</td>										
					<td style="display:none;" type="ed">14-STESO</td>
					<td style="display:none;" type="ed"></td>
					<td style="display:none;" type="ed">f</td>
					<td style="display:none;" type="ed">12</td>
					<td style="display:none;" type="ed">18000</td>
					<td style="display:none;" type="ed">{&quot;AMP&quot;:[&quot;1&quot;],&quot;BOX&quot;:[&quot;10&quot;]}</td>
				<td style="display:none;" type="ed"></td>
		</tr>
</table>
<input type="button" name="addnew" id="addnew" value="Tambah Row" onclick="addNewRow();">
</body>
<script>
function addNewRow()
{
	var i = 1;
	id = "node-"+i;
	mygrid.clearSelection();			
	mygrid.addRow(id,"");
	mygrid.selectCell(mygrid.getRowsNum()-1,3,true,true);
	mygrid.editCell();	
}

function calculateFooterValues(stage)
{
	if(stage && stage!=2)
		return true;
	//var nrQ = document.getElementById("nr_q");
		//nrQ.innerHTML = sumColumn(3)
	//var srQ = document.getElementById("sr_q");
	//	srQ.innerHTML = sumColumn(5)
	var nrS = document.getElementById("nr_s");
		nrS.innerHTML = sumColumn(5)
	var srS = document.getElementById("sr_s");
		srS.innerHTML = "Rp. "+sumIncome(2,4,5)
	return true;
}

function sumColumn(ind){
	var out = 0;
	for(var i=0;i<mygrid.getRowsNum();i++)
	{
		out+= parseFloat(mygrid.cells2(i,ind).getValue())
	}
	return out;
}

function sumIncome(indPrice,indQuant,indTuslah){
	var out = 0;
	for(var i=0;i<mygrid.getRowsNum();i++)
	{
		out+= parseFloat(mygrid.cells2(i,indPrice).getValue())*parseFloat(mygrid.cells2(i,indQuant).getValue())+parseFloat(mygrid.cells2(i,indTuslah).getValue());
	}
	return out;
}

mygrid = new dhtmlXGridFromTable('gridTransaksi');
mygrid.imgURL = "assets/dhtmlx/codebase/imgs/icons_greenfolders/";
mygrid.setImagePath("assets/dhtmlx/codebase/imgs/");
mygrid.setColTypes("ch,ro,ro,ed,ed,ed,ed,ro,edn[=c4*c6+c7],coro,coro,coro,coro,ro,ro,ro,ro,ed");
mygrid.setColSorting("str,int,str,str,int,str,int,int,int,str,str,str,str,str,str,int,str");
mygrid.setSkin("dhx_skyblue")
//mygrid.attachEvent("onEditCell",calculateFooterValues)
//mygrid.submitOnlyChanged(false);
//mygrid.setFieldName("lists[{ROW_INDEX}][]");
mygrid.setSizes();
mygrid.enableValidation(true);
mygrid.setColValidators(",,,NotEmpty,,,,ValidInteger,,,,,,,,,,");
mygrid.enableMultiselect(true);
mygrid.enableEditEvents(false,true,true);
mygrid.attachFooter("Total R/ {#stat_count},#cspan,#cspan,#cspan,#cspan,Embalase: <div id='nr_s'>0</div>,Total: <div id='sr_s'>0</div>,-,#cspan,#cspan,#cspan",["text-align:left;"])
mygrid.setMathRound(2);

regards,

Farid

error dissapear, after I add to dhtmlxgrid_form.js online 11:

function(a){if(a&&a.name)a.cell.wasChanged=true})

Thanks you,…

farid