shifted building of grid from php to js