mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT: Preserve sort options in pagination links in TableListField (from r105275)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112475 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
68fcd8c94f
commit
12fa850986
@ -792,6 +792,16 @@ JS
|
||||
$baseLink = ($this->paginationBaseLink) ? $this->paginationBaseLink : $this->Link();
|
||||
$link = Controller::join_links($baseLink, "?ctf[{$this->Name()}][start]={$start}");
|
||||
if($this->extraLinkParams) $link .= "&" . http_build_query($this->extraLinkParams);
|
||||
|
||||
// preserve sort options
|
||||
if(isset($_REQUEST['ctf'][$this->Name()]['sort'])) {
|
||||
$link .= "&ctf[{$this->Name()}][sort]=" . $_REQUEST['ctf'][$this->Name()]['sort'];
|
||||
// direction
|
||||
if(isset($_REQUEST['ctf'][$this->Name()]['dir'])) {
|
||||
$link .= "&ctf[{$this->Name()}][dir]=" . $_REQUEST['ctf'][$this->Name()]['dir'];
|
||||
}
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
@ -807,6 +817,16 @@ JS
|
||||
$baseLink = ($this->paginationBaseLink) ? $this->paginationBaseLink : $this->Link();
|
||||
$link = Controller::join_links($baseLink, "?ctf[{$this->Name()}][start]={$start}");
|
||||
if($this->extraLinkParams) $link .= "&" . http_build_query($this->extraLinkParams);
|
||||
|
||||
// preserve sort options
|
||||
if(isset($_REQUEST['ctf'][$this->Name()]['sort'])) {
|
||||
$link .= "&ctf[{$this->Name()}][sort]=" . $_REQUEST['ctf'][$this->Name()]['sort'];
|
||||
// direction
|
||||
if(isset($_REQUEST['ctf'][$this->Name()]['dir'])) {
|
||||
$link .= "&ctf[{$this->Name()}][dir]=" . $_REQUEST['ctf'][$this->Name()]['dir'];
|
||||
}
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
@ -820,6 +840,16 @@ JS
|
||||
$baseLink = ($this->paginationBaseLink) ? $this->paginationBaseLink : $this->Link();
|
||||
$link = Controller::join_links($baseLink, "?ctf[{$this->Name()}][start]={$start}");
|
||||
if($this->extraLinkParams) $link .= "&" . http_build_query($this->extraLinkParams);
|
||||
|
||||
// preserve sort options
|
||||
if(isset($_REQUEST['ctf'][$this->Name()]['sort'])) {
|
||||
$link .= "&ctf[{$this->Name()}][sort]=" . $_REQUEST['ctf'][$this->Name()]['sort'];
|
||||
// direction
|
||||
if(isset($_REQUEST['ctf'][$this->Name()]['dir'])) {
|
||||
$link .= "&ctf[{$this->Name()}][dir]=" . $_REQUEST['ctf'][$this->Name()]['dir'];
|
||||
}
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
@ -834,6 +864,16 @@ JS
|
||||
$baseLink = ($this->paginationBaseLink) ? $this->paginationBaseLink : $this->Link();
|
||||
$link = Controller::join_links($baseLink, "?ctf[{$this->Name()}][start]={$start}");
|
||||
if($this->extraLinkParams) $link .= "&" . http_build_query($this->extraLinkParams);
|
||||
|
||||
// preserve sort options
|
||||
if(isset($_REQUEST['ctf'][$this->Name()]['sort'])) {
|
||||
$link .= "&ctf[{$this->Name()}][sort]=" . $_REQUEST['ctf'][$this->Name()]['sort'];
|
||||
// direction
|
||||
if(isset($_REQUEST['ctf'][$this->Name()]['dir'])) {
|
||||
$link .= "&ctf[{$this->Name()}][dir]=" . $_REQUEST['ctf'][$this->Name()]['dir'];
|
||||
}
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
|
@ -212,6 +212,63 @@ class TableListFieldTest extends SapphireTest {
|
||||
|
||||
unlink($csvFileName);
|
||||
}
|
||||
|
||||
function testPreservedSortOptionsInPaginationLink() {
|
||||
$item1 = $this->objFromFixture('TableListFieldTest_Obj', 'one');
|
||||
$item2 = $this->objFromFixture('TableListFieldTest_Obj', 'two');
|
||||
$item3 = $this->objFromFixture('TableListFieldTest_Obj', 'three');
|
||||
$item4 = $this->objFromFixture('TableListFieldTest_Obj', 'four');
|
||||
$item5 = $this->objFromFixture('TableListFieldTest_Obj', 'five');
|
||||
|
||||
/* With pagination enabled, only the first page of items should be shown */
|
||||
$table = new TableListField("Tester", "TableListFieldTest_Obj", array(
|
||||
"A" => "Col A",
|
||||
"B" => "Col B",
|
||||
"C" => "Col C",
|
||||
"D" => "Col D",
|
||||
"E" => "Col E",
|
||||
));
|
||||
// A TableListField must be inside a form for its links to be generated
|
||||
$form = new Form(new TableListFieldTest_TestController(), "TestForm", new FieldSet(
|
||||
$table
|
||||
), new FieldSet());
|
||||
|
||||
$table->ShowPagination = true;
|
||||
$table->PageSize = 2;
|
||||
|
||||
// first page & sort A column by ASC
|
||||
$_REQUEST['ctf']['Tester']['start'] = 0;
|
||||
$_REQUEST['ctf']['Tester']['sort'] = 'A';
|
||||
$this->assertContains('&ctf[Tester][sort]=A', $table->NextLink());
|
||||
$this->assertNotContains('ctf[Tester][dir]', $table->NextLink());
|
||||
$this->assertContains('&ctf[Tester][sort]=A', $table->LastLink());
|
||||
$this->assertNotContains('ctf[Tester][dir]', $table->LastLink());
|
||||
|
||||
// second page & sort A column by ASC
|
||||
$_REQUEST['ctf']['Tester']['start'] = 2;
|
||||
$this->assertContains('&ctf[Tester][sort]=A', $table->PrevLink());
|
||||
$this->assertNotContains('&ctf[Tester][dir]', $table->PrevLink());
|
||||
$this->assertContains('&ctf[Tester][sort]=A', $table->FirstLink());
|
||||
$this->assertNotContains('&ctf[Tester][dir]', $table->FirstLink());
|
||||
|
||||
// first page & sort A column by DESC
|
||||
$_REQUEST['ctf']['Tester']['start'] = 0;
|
||||
$_REQUEST['ctf']['Tester']['sort'] = 'A';
|
||||
$_REQUEST['ctf']['Tester']['dir'] = 'desc';
|
||||
$this->assertContains('&ctf[Tester][sort]=A', $table->NextLink());
|
||||
$this->assertContains('&ctf[Tester][dir]=desc', $table->NextLink());
|
||||
$this->assertContains('&ctf[Tester][sort]=A', $table->LastLink());
|
||||
$this->assertContains('&ctf[Tester][dir]=desc', $table->LastLink());
|
||||
|
||||
// second page & sort A column by DESC
|
||||
$_REQUEST['ctf']['Tester']['start'] = 2;
|
||||
$this->assertContains('&ctf[Tester][sort]=A', $table->PrevLink());
|
||||
$this->assertContains('&ctf[Tester][dir]=desc', $table->PrevLink());
|
||||
$this->assertContains('&ctf[Tester][sort]=A', $table->FirstLink());
|
||||
$this->assertContains('&ctf[Tester][dir]=desc', $table->FirstLink());
|
||||
|
||||
unset($_REQUEST['ctf']);
|
||||
}
|
||||
}
|
||||
|
||||
class TableListFieldTest_Obj extends DataObject implements TestOnly {
|
||||
|
Loading…
Reference in New Issue
Block a user