Custom grid working for both horizontal and vertical directions.