I've narrowed down the issue a bit.
I am calling a function in beforeTableView:
obj.beforeTableView = function (event, ui) {
Validate();
};
Among other things it adds/removes classes on some cells like so:
grid.Container.pqGrid("addClass", { rowIndx: rowIndx, dataIndx: column.dataIndx, cls: 'gridCellValidationFailed' });
When all the cells are 0 or null, no validations are run so the part of the function where classes are added/removed is not reached and that's why the error does not happen. However if there is data then the error happens.
Also if I load a blank grid successfully, and then update the underlying data, followed by:
grid.Container.pqGrid('refreshDataAndView');
then everything works fine.