DataGrid Search: Object Reference Error

The DataGrid search is implemented using a library called Lucene. Whenever users perform a search, Stadium passes the search value to Lucene and Lucene filters the DataGrid data.

Whenever Lucene returns an error, it is shown in red under the search field.

Most often the cause of errors are the use of reserved characters or invalid search syntax entered by the user, but the main cause of the “Object reference” error shown above is a problem with the integrity of the data.

Let’s assume we have a DataGrid with the columns “ID”, “FirstName” and “LastName”, but yoru data is missing a property – like the LastName property in the second item below:

[
	{
		"ID": 1,
		"FirstName": null,
		"LastName": ""
	},
	{
		"ID": 2,
		"FirstName": "dfg",
	}
]

Assigning the data the DataGrid will work fine and empty cells will be shown wherever there are missing properties. However, searches on such a DataGrid will result in the “Object reference” error shown above.

So, while it is fine to assign ‘null’ or an empty string to properties is fine, but leaving properties out altogether is not. In this case, the first thing to do is to check the point where the data is assigned to the array and make sure each array item has a property for every column in the DataGrid.

If you are not sure which property or is missing, you can use the script below to verify the integrity of the data. The repo explains how to use the script. This script loops through each object in the data array, which can notably slow things down and should therefor only be used for debugging purposes.