new grouping algorithm for grid rows