Get the sort buttons to add under the table with sortable rows

@param string $sortAction The name of the ajax action
@param string $urlIdParam The namr used to refer to the record ID in the url
@return MUtil_Html_HtmlElement
355206
public function direct($sortAction = 'sort', $urlIdParam = 'id')
    {
        $view = $this->getView();
        \MUtil_JQuery::enableView($view);

        $jquery = $view->jQuery();
        $jquery->enable();  //Just to make sure

        $handler = \ZendX_JQuery_View_Helper_JQuery::getJQueryHandler();
        $url     = $view->serverUrl() . $view->baseUrl() . '/' . $this->getRequest()->getControllerName() . '/' . $sortAction;

        $script = file_get_contents(__DIR__ . '/js/SortableTable.js');
        $fields = array(
            'jQuery'  => $handler,
            'AJAXURL' => $url,
            'IDPARAM' => $urlIdParam
        );

        $js = str_replace(array_keys($fields), $fields, $script);

        $jquery->addOnLoad($js);

        $buttons        = \Mutil_Html::div();
        $buttons->class = 'buttons pull-right';

        $buttons->div($this->getActionController()->_('Sort'), array('id' => 'sort', 'class' => "btn"));
        $buttons->div($this->getActionController()->_('Ok'), array('id' => 'sort-ok', 'class' => "btn btn-success", 'style' => 'display:none;'));
        $buttons->div($this->getActionController()->_('Cancel'), array('id' => 'sort-cancel', 'class' => "btn btn-warning", 'style' => 'display:none;'));

        return $buttons;
    }
366972
public function getQueryPagination(ModuleActionsInterface $entity, $sort, $direction)
    {

        $queryBuilder = $this->createQueryBuilder('m');

        $data = [
            'name' => $entity->getName(),
            'identifier' => $entity->getIdentifier(),
            'module'     => !is_null($entity->getModule()) ? $entity->getModule() :  '',
            'id' => $entity->getId(),
        ];

        if (!empty($entity->getModule())) {
            $queryBuilder
                ->andWhere($queryBuilder->expr()->eq('m.module', ':module'))
                ->setParameter('module', $data['module'])
            ;
        }

        if (!empty($data['id'])) {
            $queryBuilder
                ->andWhere($queryBuilder->expr()->eq('m.id', ':id'))
                ->setParameter('id', $data['id'])
            ;
        }

        if (!empty($data['name'])) {
            $queryBuilder
                ->andWhere($queryBuilder->expr()->like('m.name', ':name'))
                ->setParameter('name', "%{$data['name']}%")
            ;
        }

        if (!empty($data['identifier'])) {
            $queryBuilder
                ->andWhere($queryBuilder->expr()->like('m.identifier', ':identifier'))
                ->setParameter('identifier', "%{$data['identifier']}%")
            ;
        }

        return $queryBuilder
            ->orderBy('m.'.$sort, $direction)
            ->getQuery()
            ;
    }
1005866
public function getActionLinks($remove, $contr1, $action1 = null, $contr2 = null, $action2 = null)
    {
        $args    = func_get_args();
        $count   = func_num_args();
        $results = new \MUtil_Html_Sequence();
        $results->setGlue($this->getGlue());

        for ($i = 1; $i < $count; $i += 2) {
            $controller = $args[$i];
            $action     = $args[$i + 1];
            $result     = $this->getActionLink($controller, $action, $remove);
            if ($result) {
                $results[$this->_getKey($controller, $action)] = $result;
            }
        }

        return $results;
    }
193623
public function getSortConditions()
    {
        if (is_array($this->sortConditions)) {
            return $this->sortConditions;
        }

        $request = $this->getRequest();

        $optionsRenderer = $this->getOptionsRenderer();
        $parameterNames = $optionsRenderer['parameterNames'];

        $sortConditions = [];

        $sortColumns = $request->getParam($parameterNames['sortColumns']);
        $sortDirections = $request->getParam($parameterNames['sortDirections']);
        if ($sortColumns != '') {
            $sortColumns = explode(',', $sortColumns);
            $sortDirections = explode(',', $sortDirections);

            foreach ($sortColumns as $key => $sortColumn) {
                if (isset($sortDirections[$key])) {
                    $sortDirection = strtoupper($sortDirections[$key]);
                } else {
                    $sortDirection = 'ASC';
                }

                if ($sortDirection != 'ASC' && $sortDirection != 'DESC') {
                    $sortDirection = 'ASC';
                }

                foreach ($this->getColumns() as $column) {
                    /* @var $column \ZfcDatagrid\Column\AbstractColumn */
                    if ($column->getUniqueId() == $sortColumn) {
                        $sortConditions[] = [
                            'sortDirection' => $sortDirection,
                            'column' => $column,
                        ];

                        $column->setSortActive($sortDirection);
                    }
                }
            }
        }

        if (! empty($sortConditions)) {
            $this->sortConditions = $sortConditions;
        } else {
            // No user sorting -> get default sorting
            $this->sortConditions = $this->getSortConditionsDefault();
        }

        return $this->sortConditions;
    }
1071141
private static function buildQueryString($queryParameters, $sortParameter, $direction)
    {
        $checkStrlenOrArray = function ($element) {
            return is_array($element) ? $element : strlen($element);
        };

        $persistParameters = array_filter(request()->except('sort', 'direction', 'page'), $checkStrlenOrArray);
        $queryString       = http_build_query(array_merge($queryParameters, $persistParameters, [
            'sort'      => $sortParameter,
            'direction' => $direction,
        ]));

        return $queryString;
    }
1071850
public function ajaxAction($table, $idField, $orderField)
    {
        $request = $this->getRequest();
        if ($request->isPost()) {
            $ids = $request->getPost('ids');
            foreach($ids as $id) {
                $cleanIds[] = (int) $id;
            }
            $db = $this->getActionController()->db;
            $select = $db->select()->from($table, array($idField, $orderField))
                    ->where($idField . ' in(?)', $cleanIds)
                    ->order($orderField);

            $oldOrder = $db->fetchPairs($select);

            if(count($oldOrder) == count($cleanIds)) {
                $newOrder = array_combine($cleanIds, $oldOrder);

                $changed = 0;
                foreach($newOrder as $id => $order)
                {
                    $changed = $changed + $db->update($table,
                            array($orderField => $order),
                            $db->quoteInto($idField . ' = ?', $id)
                            );
                }

                $this->getActionController()->addMessage(sprintf($this->getActionController()->plural('%s record updated due to sorting.', '%s records updated due to sorting.', $changed), $changed));

                return;
            }
        }

        throw new \Gems_Exception($this->_('Sorting failed'), 403);
    }
1292847
function (sortableElement) {
        var opts = addData(sortableElement, 'opts');
        var items = _filter(sortableElement.children, opts.items);
        var handles = _getHandles(items, opts.handle);
        addAttribute(sortableElement, 'aria-dropeffect', 'move');
        addData(sortableElement, '_disabled', 'false');
        addAttribute(handles, 'draggable', 'true');
        // @todo: remove this fix
        // IE FIX for ghost
        // can be disabled as it has the side effect that other events
        // (e.g. click) will be ignored
        if (opts.disableIEFix === false) {
            var spanEl = (document || window.document).createElement('span');
            if (typeof spanEl.dragDrop === 'function') {
                addEventListener(handles, 'mousedown', function () {
                    if (items.indexOf(this) !== -1) {
                        this.dragDrop();
                    }
                    else {
                        var parent = this.parentElement;
                        while (items.indexOf(parent) === -1) {
                            parent = parent.parentElement;
                        }
                        parent.dragDrop();
                    }
                });
            }
        }
    }
579813
public void sortTypes(String sortParams) {

        List<CmsResourceTypeBean> types = getSearchTypes();
        SortParams sort = SortParams.valueOf(sortParams);
        switch (sort) {
            case title_asc:
                Collections.sort(types, new CmsComparatorTitle(true));
                break;
            case title_desc:
                Collections.sort(types, new CmsComparatorTitle(false));
                break;
            case type_asc:
                Collections.sort(types, new CmsComparatorType(true));
                break;
            case type_desc:
                Collections.sort(types, new CmsComparatorType(false));
                break;
            case dateLastModified_asc:
            case dateLastModified_desc:
            case path_asc:
            case path_desc:
            case tree:
            default:
                // not supported
                return;
        }
        m_handler.onUpdateTypes(types, m_searchObject.getTypes());
    }
997953
public function jsJsonArray($url, $method="get", $params="{}", $jsCallback=NULL,$parameters=[]){
		$parameters=\array_merge($parameters,["modelSelector"=>"#".$this->_identifier." tr.".$this->_modelClass,"url"=>$url,"method"=>$method,"params"=>$params,"jsCallback"=>$jsCallback]);
		return new AjaxCall("jsonArray", $parameters);
	}
572050
function onSortableClick( event ) {
  if ( this.ui.sortButton ) {
    this.ui.sortButton.classList.remove( this.sortClass );
  }
  if ( this.ui.sortButton === event.target ) {
    this.sortDirection = ~this.sortDirection;
  } else {
    this.ui.sortButton = event.target;
    this.sortColumnIndex = this.getColumnIndex();
    this.sortDirection = DIRECTIONS.UP;
  }
  // The active sort class is changing when the sort direction changes.
  this.ui.sortButton.classList.add( this.sortClass );
  this.updateTable();

  return this;
}
1107759
private function update($model, $sortableAttribute, $sortOrderData)
	{
		$pk = $model->tableSchema->primaryKey;
		$pk_array = array();
		if(is_array($pk)) { // composite key
			$string_ids = array_keys($sortOrderData);
			
			$array_ids = array();
			foreach ($string_ids as $string_id)
				$array_ids[] = explode(',', $string_id);
			
			foreach ($array_ids as $array_id)
				$pk_array[] = array_combine($pk, $array_id);
		} else { // normal key
			$pk_array = array_keys($sortOrderData);
		}
		
		$models = $model->model()->findAllByPk($pk_array);
		$transaction = Yii::app()->db->beginTransaction();
		try {
			foreach ($models as $model) {
				$_key = is_array($pk) ? implode(',', array_values($model->primaryKey)) : $model->primaryKey;
				$model->{$sortableAttribute} = $sortOrderData[$_key];
				$model->save();
			}
			$transaction->commit();
		}
		catch(Exception $e) { // an exception is raised if a query fails
			$transaction->rollback();
		}
	}
1345679
public function indexAction()
    {
        /* @todo: move this into a listener.
         *
         * The following lines allow to override get param[q] with the
         * param from route. This feature is needed for a landing-page feature, where
         * human readable urls like http://yawik.org/demo/de/jobs/sales.html
         *
         * move the Logic into a Listener, which can be activated, if needed
         */
        $request = $this->getRequest();
        $getParams = $request->getQuery();
        $routeParams = $this->params()->fromRoute();
        if (isset($routeParams['q']) && !isset($getParams['q'])) {
            $getParams['q']=$routeParams['q'];
        }

        $result = $this->pagination([
                'params' => ['Jobs_Board', [
                    'q',
                    'count' => $this->options['count'],
                    'page' => 1,
                    'l',
                    'd' => 10]
                ],
                'form' => ['as' => 'filterForm', 'Jobs/JobboardSearch'],
                'paginator' => ['as' => 'jobs', 'Jobs/Board']
            ]);

        $organizationImageCache = $this->imageFileCacheManager;

        $result['organizationImageCache'] = $organizationImageCache;

        return new ViewModel($result);
    }
1323826
public function listView(CrudConfigurator $crudConfigurator, array $gridFields, $allowBulkDelete, $formatNumber)
    {
        $crud = $crudConfigurator->getCrud();
        /** @var ListActionHandler $viewHandler */
        $viewHandler = $this->actionHandlers[ListActionHandler::class];
        $viewHandler->setModelClass($crud->getModelClass());
        $viewHandler->setView($this->view);
        $viewHandler->setRequest($this->request);
        $viewHandler->setGridFields($gridFields);
        $viewHandler->setActionList($crudConfigurator->getGridAction());
        $viewHandler->isAllowCrate($crud->isAllowCreate());
        $viewHandler->isAllowBulkDelete($allowBulkDelete);
        $viewHandler->isFormatNumber($formatNumber);
        $viewHandler->setListHandler($crud->getListHandler());

        return $this->getResponse($viewHandler->getView($this->driver));
    }
344054
public function handleAction($action, $actionParams)
    {
        $this->setView($action);
        $response = parent::handleAction($action, $actionParams);

        if ($response instanceof Response) {
            return $response;
        }

        if (is_string($response)) {
            $this->controllerView->content = $response;
        } elseif (isset($this->view)) {
            $this->controllerView->content = $this->view->render();
        }

        $this->response->setContent($this->controllerView->render());

        return $this->response;
    }
144597
public function sortable($sortable)
    {
        foreach ($sortable as $column => $options) {
            $this->sortable[$column] = $options;
        }

        return $this;
    }
510300
public function getFiltered($page, $numRows, $sortAttr, $sortOrder, $searchAttr, $searchValue, $richFilters = [])
    {
        $query = $this->prepareQuery();

        $query = $this->richFiltersOnQuery($query, $richFilters);

        if ($sortAttr && $sortOrder && $this->inScope($sortAttr)) {
            $scope = $this->getScope($sortAttr);
            $query = $query->orderBy($scope, $sortOrder);
        }

        if ($searchAttr && $searchValue && $this->inScope($searchAttr)) {
            $scope = $this->getScope($searchAttr);
            $query = $query->where($scope, 'like', '%' . $searchValue . '%');
        }

        $collection = $query->get();

        $collection = $this->addPermissions($collection);

        $collection = $this->formatCollection($collection);

        $collection = $collection->each(function ($model) {
            $model = $this->formatModel($model);
        });

        if ($sortAttr && $sortOrder && ! $this->inScope($sortAttr)) {
            $collection = $sortOrder == 'asc'
                ? $collection->sortBy($sortAttr)
                : $collection->sortByDesc($sortAttr);
        }

        $collection = $this->richFiltersOnCollection($collection, $richFilters);

        if ($searchAttr && $searchValue && ! $this->inScope($searchAttr)) {
            $collection = $collection->filter(function ($model) use ($searchAttr, $searchValue) {
                $value = (string) $model->$searchAttr;
                $value = strtolower($value);
                $search = strtolower($searchValue);
                return strpos($value, $search) !== false;
            });
        }

        if ($page && $numRows) {
            $toSkip = ($page - 1) * $numRows;
            $count = $collection->count();
            $collection = $collection->take(- ($count - $toSkip))->take($numRows);
        } else if ($numRows)
            $collection = $collection->take($numRows);

        return collect(array_values($collection->toArray()));
    }
907663
public function search(Search $entity, $limit, $offset, $sort_column, $sort_direction)
    {
        $selector = $this->selector
            ->create()
            ->addCountry($entity)
            ->addDateAdd($entity)
            ->addDateEnd($entity)
            ->addDatePremiere($entity)
            ->addGenres($entity)
            ->addLabels($entity)
            ->addName($entity)
            ->addStorage($entity)
            ->addStudio($entity)
            ->addType($entity)
            ->sort($sort_column, $sort_direction)
            ->limit($limit)
            ->offset($offset);

        return [
            'list' => $selector
                ->getQuerySelect()
                ->getQuery()
                ->getResult(),
            'total' => $selector
                ->getQueryTotal()
                ->getQuery()
                ->getSingleScalarResult(),
        ];
    }