Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

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

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

ComplexTableField and Search


Go to End
Reply


3 Posts   1413 Views

Avatar
adesweb

Community Member, 39 Posts

11 September 2008 at 9:57pm

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

Avatar
adesweb

Community Member, 39 Posts

12 September 2008 at 9:26pm

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

Adrian

Avatar
Fuzz10

Community Member, 787 Posts

12 September 2008 at 9:53pm

Hi Adrian,

Would you mind posting the solution ?