Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

FEATURE SSF-25 : change to use GridField for showing searched results…

… in stead of TableListField
  • Loading branch information...
commit d24c2ef1edd956b6f63abbef022f6b4abb5785b8 1 parent 7d956de
@normann normann authored
Showing with 11 additions and 41 deletions.
  1. +11 −41 admin/code/ModelAdmin.php
View
52 admin/code/ModelAdmin.php
@@ -125,7 +125,7 @@
* Class name of the form field used for the results list. Overloading this in subclasses
* can let you customise the results table field.
*/
- protected $resultsTableClassName = 'TableListField';
+ protected $resultsTableClassName = 'GridField';
/**
* Return {@link $this->resultsTableClassName}
@@ -651,19 +651,6 @@ public function ColumnSelectionField() {
function search($request, $form) {
// Get the results form to be rendered
$resultsForm = $this->ResultsForm(array_merge($form->getData(), $request));
- // Before rendering, let's get the total number of results returned
- $tableField = $resultsForm->Fields()->dataFieldByName($this->modelClass);
- $tableField->addExtraClass('resultsTable');
- $numResults = $tableField->TotalCount();
-
- if($numResults) {
- $msg = sprintf(
- _t('ModelAdmin.FOUNDRESULTS',"Your search found %s matching items"),
- $numResults
- );
- } else {
- $msg = _t('ModelAdmin.NORESULTS',"Your search didn't return any matching items");
- }
return new SS_HTTPResponse(
$resultsForm->forTemplate(),
200,
@@ -715,37 +702,21 @@ function getResultColumns($searchCriteria, $selectedOnly = true) {
*
* @param array $searchCriteria passed through from ResultsForm
*
- * @return TableListField
+ * @return GridField
*/
function getResultsTable($searchCriteria) {
- $summaryFields = $this->getResultColumns($searchCriteria);
-
$className = $this->parentController->resultsTableClassName();
- $tf = new $className(
- $this->modelClass,
+ $datalist = $this->getSearchQuery($searchCriteria);
+ $tf = Object::create($className,
$this->modelClass,
- $summaryFields
- );
-
- $tf->setCustomQuery($this->getSearchQuery($searchCriteria));
- $tf->setPageSize($this->parentController->stat('page_length'));
- $tf->setShowPagination(true);
- // @todo Remove records that can't be viewed by the current user
- $tf->setPermissions(array_merge(array('view','export'), TableListField::permissions_for_object($this->modelClass)));
-
- // csv export settings (select all columns regardless of user checkbox settings in 'ResultsAssembly')
- $exportFields = $this->getResultColumns($searchCriteria, false);
- $tf->setFieldListCsv($exportFields);
-
- $url = '<a href=\"' . $this->Link() . '/$ID/edit\">$value</a>';
- if(count($summaryFields)) {
- $tf->setFieldFormatting(array_combine(
- array_keys($summaryFields),
- array_fill(0,count($summaryFields), $url)
- ));
- }
-
+ false,
+ $datalist,
+ $fieldConfig = GridFieldConfig_RecordEditor::create()
+ ->addComponent(new GridFieldExporter())
+ )->setDisplayFields($this->getResultColumns($searchCriteria));
+
+ $fieldConfig->getComponentByType('GridFieldPaginator')->setItemsPerPage($this->parentController->stat('page_length'));
return $tf;
}
@@ -757,7 +728,6 @@ function getResultsTable($searchCriteria) {
* @return Form
*/
function ResultsForm($searchCriteria) {
-
if($searchCriteria instanceof SS_HTTPRequest) $searchCriteria = $searchCriteria->getVars();
$tf = $this->getResultsTable($searchCriteria);
Please sign in to comment.
Something went wrong with that request. Please try again.