Grid's reference and a callback of removeData

I am trying to have code that will delete records from ListGrid that is bound to local data. And if the last record is removed start editing a new one.
cellClick:

function (record, rowNum, colNum)
{
        if (colNum == 4 && record != null)
        {
	        record.file_id = -1;
	        this.removeData(record, 
	        function ()
	            {
		        if (this.data.getLength() == 0)				        		this.startEditingNew();
	            }
                     );
}

This code does remove the record, it also works at this.data.getLength() while showing 1 even when it is last record that has been removed, but at this.startEditingNew() it fails saying no such property.
Could you help?

Thanks

In an anonymous function like that, “this” is the global “window” object. This is just how the JavaScript language works.

An idiom to deal to deal is to create a local variable with the value of whatever component you need.

function (record, rowNum, colNum)
{
        if (colNum == 4 && record != null)
        {
	        record.file_id = -1;
                [b]var grid = this;[/b]
	        this.removeData(record, 
	        function ()
	            {
		        if ([b]grid[/b].data.getLength() == 0)
	        		[b]grid[/b].startEditingNew();
	            }
                     );
}

I think I tried that but will do again, thanks.

Yes, it works, great. The only confusing thing there is that when I delete the last record grid.data.getLength() still returns 1.