/**
  * Select handler, returns the records for the grid.
  *
  * @param DataGrid $grid
  *
  * @return array Records for the grid
  */
 public function selectHandlerForAdd(DataGrid $grid)
 {
     $records = $this->getRecordsFromSession();
     $limit = $grid->getLimit();
     $offset = $grid->getOffset();
     $records_count = count($records);
     // If we don't need to limit the result, then we don't
     if ((int) $offset === 0 && $limit >= $records_count) {
         // We have to sort the data first, because the datagrid
         // is very sensitive with regards to it's numerical keys
         // being sequential
         sort($records);
         return $records;
     }
     // Limit the search results and return the limited results
     $ret = [];
     $records_keys = array_keys($records);
     for ($i = $offset, $j = 0; $i < $records_count && $j < $limit; $i++, $j++) {
         $ret[] = $records[$records_keys[$i]];
     }
     return $ret;
 }