I got this error because I set the number of columns by defining the column headers in mygrid.setHeader(), but the number of columns was different when I called other functions like mygrid.setColTypes() and mygrid.setColSorting().
When I initialized the grid, it threw this error. It was a bug in my code that lead to different column numbers, but the error was very unhelpful to me in tracking down the issue.
So, this post is really just a way to help myself (or someone else) in the future if it comes up again.