TreeGrid getRecordIndex always returns -1

I’m posting this in case anyone is having the same problem.
It seems that getRecordIndex method works only with currently opened nodes according to this
Open all nodes before using getRecordIndex. Just call “TreeGrid.getData().openAll()” after data has been fetched.

treeGrid.fetchData(new Criteria(),new DSCallback() {
	@Override
	public void execute(DSResponse response, Object rawData, DSRequest request) {
		treeGrid.getData().openAll();
	}
});