Ejemplo n.º 1
0
 /**
  * @param  DataGrid $grid
  * @param  Column $column
  * @param  int $mode
  * @return string
  */
 public static function createSortLink(DataGrid $grid, Column $column, $mode = self::SORT_LINK_SINGLE)
 {
     if ($mode === self::SORT_LINK_SINGLE) {
         $by = array();
         if (!$column->sortedBy || count($grid->orderBy) > 1) {
             $by[$column->name] = Column::ASC;
         } elseif ($column->sortedBy && $column->sortDir === Column::ASC) {
             $by[$column->name] = Column::DESC;
         }
     } elseif ($mode === self::SORT_LINK_MULTI) {
         $by = $grid->orderBy;
         if (!$column->sortedBy) {
             $by[$column->name] = Column::ASC;
         } elseif ($column->sortDir === Column::ASC) {
             $by[$column->name] = Column::DESC;
         } else {
             unset($by[$column->name]);
         }
     }
     return $grid->link('sort!', array('orderBy' => $by));
 }
Ejemplo n.º 2
0
 /**
  * @param  DataGrid $grid
  * @param  Column $column
  * @param  int $mode
  * @return string
  */
 public static function createSortLink(DataGrid $grid, Column $column, $mode = self::SORT_LINK_SINGLE)
 {
     if ($mode === self::SORT_LINK_SINGLE) {
         $by = [];
         if (!$column->isSortedBy() || count($grid->orderBy) > 1) {
             $by[$column->getName()] = Column::ASC;
         } elseif ($column->isSortedBy() && $column->getSortDir() === Column::ASC) {
             $by[$column->getName()] = Column::DESC;
         }
     } elseif ($mode === self::SORT_LINK_MULTI) {
         $by = $grid->orderBy;
         if (!$column->isSortedBy()) {
             $by[$column->getName()] = Column::ASC;
         } elseif ($column->getSortDir() === Column::ASC) {
             $by[$column->getName()] = Column::DESC;
         } else {
             unset($by[$column->getName()]);
         }
     }
     return $grid->link('sort!', ['orderBy' => $by]);
 }