Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » ComplexTableField and Search

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 1317 Views
  • adesweb
    Avatar
    Community Member
    39 Posts

    ComplexTableField and Search Link to this post

    Anyone have experience of adding a search box on top of a complexTableField, so you can search within the table?

    I have tried using the code for MemberTableField to do it, but keep running into issues.

    Any help would be gratefully received,

    This is what I have so far:

    /**
    * Extends a ComplexTableField by adding a search box to search within the table
    *
    */

    class SearchComplexTableField extends ComplexTableField {
       
       /**
        * Template for main rendering
        *
        * @var string
        */
       protected $template = "SearchComplexTableField";

       function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
          parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
          
          // search
          $SQL_search = isset($_REQUEST['TableSearch']) ? Convert::raw2sql($_REQUEST['TableSearch']) : null;
          if(!empty($_REQUEST['TableSearch'])) {
             $searchFilters = array();
             foreach($fieldList as $fieldName => $fieldSpec) {
                $searchFilters[] = "`$fieldName` LIKE '%{$SQL_search}%'";
             }
             $this->sourceFilter[] = '(' . implode(' OR ', $searchFilters) . ')';
             
          }
       }
       
       function SearchForm() {
          $searchFields = new FieldGroup(
             new TextField('TableSearch', _t('TableField.SEARCH', 'Search'))
          );

          $actionFields = new LiteralField('ComplexTableFilterButton','<input type="submit" class="action" name="ComplexTableFilterButton" value="'._t('SearchComplexTableField.FILTER', 'Filter').'" id="ComplexTableFilterButton"/>');

          $fieldContainer = new FieldGroup(
                $searchFields,
                $actionFields
          );

          return $fieldContainer->FieldHolder();
       }

    }

    I get an error about missing Action.

    Can someone point me in the right direction,

    Thanks,

    Adrian

  • adesweb
    Avatar
    Community Member
    39 Posts

    Re: ComplexTableField and Search Link to this post

    I have since managed to get this working. If anyone needs the solution, let me know.

    Adrian

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: ComplexTableField and Search Link to this post

    Hi Adrian,

    Would you mind posting the solution ?

    1317 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.