mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Make TableListField sort checking use SQLQuery::canSortBy() to let SSReprot_FakeQuery work.
ENHANCEMENT: Allow sort descending as well as ascending. (from r96054) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@98132 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
1434fae6cf
commit
55423c1547
@ -319,10 +319,13 @@ JS
|
||||
if($this->form) {
|
||||
$sortLink = $this->Link();
|
||||
$sortLink = HTTP::setGetVar("ctf[{$this->Name()}][sort]", $fieldName, $sortLink);
|
||||
if(isset($_REQUEST['ctf'][$this->Name()]['dir'])) {
|
||||
$XML_sort = (isset($_REQUEST['ctf'][$this->Name()]['dir'])) ? Convert::raw2xml($_REQUEST['ctf'][$this->Name()]['dir']) : null;
|
||||
$sortLink = HTTP::setGetVar("ctf[{$this->Name()}][dir]", $XML_sort, $sortLink);
|
||||
}
|
||||
|
||||
// Apply sort direction
|
||||
$dir = isset($_REQUEST['ctf'][$this->Name()]['dir']) ? $_REQUEST['ctf'][$this->Name()]['dir'] : null;
|
||||
$dir = trim(strtolower($dir));
|
||||
$newDir = ($dir == 'desc') ? null : 'desc';
|
||||
$sortLink = HTTP::setGetVar("ctf[{$this->Name()}][dir]", Convert::raw2xml($newDir), $sortLink);
|
||||
|
||||
if(isset($_REQUEST['ctf'][$this->Name()]['search']) && is_array($_REQUEST['ctf'][$this->Name()]['search'])) {
|
||||
foreach($_REQUEST['ctf'][$this->Name()]['search'] as $parameter => $value) {
|
||||
$XML_search = Convert::raw2xml($value);
|
||||
@ -480,13 +483,13 @@ JS
|
||||
$query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter(), $this->sourceSort, null, $this->sourceJoin);
|
||||
}
|
||||
|
||||
if(isset($_REQUEST['ctf'][$this->Name()]['sort'])) {
|
||||
$SQL_sort = Convert::raw2sql($_REQUEST['ctf'][$this->Name()]['sort']);
|
||||
$sql = $query->sql();
|
||||
// see {isFieldSortable}
|
||||
if(in_array($SQL_sort,$query->select) || stripos($sql,"AS {$SQL_sort}")) {
|
||||
$query->orderby = $SQL_sort;
|
||||
if(!empty($_REQUEST['ctf'][$this->Name()]['sort'])) {
|
||||
$sort = $_REQUEST['ctf'][$this->Name()]['sort'];
|
||||
if(!empty($_REQUEST['ctf'][$this->Name()]['dir'])) {
|
||||
$dir = $_REQUEST['ctf'][$this->Name()]['dir'];
|
||||
if(strtoupper(trim($dir)) == 'DESC') $sort .= ' DESC';
|
||||
}
|
||||
if($query->canSortBy($sort)) $query->orderby = $sort;
|
||||
}
|
||||
|
||||
return $query;
|
||||
|
Loading…
Reference in New Issue
Block a user