Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Johny on May 13, 2008 10:28
open dhtmlx forum
Add and Delete Rows Bug ?

I noticed getting a bug by deleting an row after adding it.
The bug can be reproduced by using the example pages

for Using Grid Api Methods on
http://www.dhtmlx.com/docs/products/dhtmlxGrid/samples/rows_columns_manipulations/api_grid.html?un=1210699101000
First Run
clearAll
addRow
addRow
deleteSelectedItem

afterMouseover on the left back line a javascript alert pops up
ErrorType: Cell
Description: Row not exists

System Windows XP
Browser Internet Explorer 5.5 or Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14

I reporduced code by own code aswell using
mygrid.addRow();
mygrid.deleteRow(); api functions
is there a workaround or bugfix?

Answer posted by Support on May 14, 2008 06:20
The problem not in component, but in sample
The addRow command inside sample uses the same ID for all rows which is incorrect ( IDs must be unique ) and cause described error.
We well update sample, to prevent confusion, in nearest time.
Answer posted by Johny on May 14, 2008 06:24
Well but i have the same problem in my own code.
How do i generate a unique id for a new row? And maybe delete it afterwards ?

Answer posted by Support on May 14, 2008 07:53
the simplest way to get unique ID is
    mygrid.getUID();
just use it instead of hardcoded value in addRow command

If you have unique ID's for each row, there must not be any problems with row deleting.
Answer posted by Johny on May 14, 2008 08:27
I am not sure if it fixes my problem completly but there is an unwished behavior.
The getUID is not doing an addition to the number of rows it is doing an string concat with one
var rowId=mygrid.getUID();       
mygrid.addRow(rowId,'',0);
alert('adding row with id'+rowId);
rowId=mygrid.getUID();       
mygrid.addRow(rowId,'',0);
alert('adding row with id'+rowId);

is returning
"adding row with id 1001"
"adding row with id 10011"
on a 100 row grid

Firebug also reports me an error on dhtmlxgrid line 815
r has no properties
selectCell(undefined, 0, false, undefined, false, undefined)dhtmlxgrid.js (line 815)
selectRow(undefined, undefined, undefined, undefined)dhtmlxgrid.js (line 970)
xgridAddRow()xclusionlist_main... (line 814)
onclick(click clientX=0, clientY=0)xclusionlist_main... (line 1)
var c = r.childNodes[cInd];




Answer posted by Support on May 14, 2008 09:36
>>The getUID is not doing an addition to the number of rows it is doing an string concat with one
Basically the logic of UID is next
    - get max count of rows
    - if such ID already exists add "1" ( as a string )  while ID not unique

If you need some other logic - you can use any custom way to generate IDs ( the ID may contain any combination of digits|chars  while it unique )

>>Firebug also reports me an error on dhtmlxgrid line 815
It seems that you have call of selectRow functionality after adding new row, please be sure that it used with correct parameters