Solution for ‘previousSibling’ is null or not an object error in grouped UltraWebGrid

Infragistics UltraWebGrid offers standard keyboard navigation for record selection. For example you can click a row, and holding Shift key press Down Arrow to select multiple records. This works fine for a flat grid, but try this with grid in OutlookGroupBy mode and you’ll get an error ‘previousSibling’ is null or not an object:

Error selecting records in grouped UltraWebGrid

After some digging I found the culprit. Take a look at Infragistics function igtbl_getBandFAC (it’s located in ig_WebGrid.js):

function igtbl_getBandFAC(gn, elem)
	var gs = igtbl_getGridById(gn);
	var bandNo = null;
	if (elem.tagName == "TD" || elem.tagName == "TH")
		if ( != "")
		{ return igtbl_getBandById(; }
		else { elem = elem.parentNode; }
	if (elem.tagName == "TR")
		bandNo = elem.parentNode.parentNode.getAttribute("bandNo");
	if (elem.tagName == "TABLE")
		bandNo = elem.getAttribute("bandNo");
	if (bandNo)
		return gs.Bands[bandNo].firstActiveCell;
	return null;

Note line 16 – it checks if bandNo is not null, and if that’s the case – returns result. For a flat grid bandNo is “0”, so condition is met and result is returned. For a grouped grid bandNo is also zero, but it is numeric 0, not string “0”! The condition on line 16 fails (if (0) is false) and null is returned, causing cascading chain of events and the error as final result.

And this is why, children, it is important when checking for null use if(value != null) instead of just if(value).

There’re several ways to fix that problem, for example write our own version of igtbl_getBandFAC function with correct null handling. But if possible, it is preferable not to hack Infragistics code – future updates may break the hack. Instead, we can assign “bandNo” a string value of “0” and this can be done in our own code. One place this can be done is BeforeRowExpanded client-side event:

function BeforeRowExpandedHandler(gridName, rowId){
    var oGroupRow = igtbl_getRowById(rowId);
    oGroupRow.getChildRows()[0].parentElement.parentElement.setAttribute('bandNo', '0');

The code is very simple, it gets reference to group row and then drills down to DOM element that holds table with child rows. It then assigns string value of “0” to attribute “bandNo”. As a result – keyboard selection is performed without errors:

Correct record selection in grouped UltraWebGrid

Leave a Reply

Your email address will not be published. Required fields are marked *