Actions

J2.5

Difference between revisions of "How to add custom filters to components"

From Joomla! Documentation

m (moving overview heading to next line)
(Extra: highlighting: css for highlighting + better tags)
Line 165: Line 165:
 
</source>
 
</source>
  
=== Extra: highlighting===
+
=== Extra: highlighting search terms ===
Here is some extra to make your fields highlight the found search terms.<br/>
+
Here is some extra to visually mark the found search terms in the results page.<br/>
<u>Add this somewhere at top of your template:</u><source lang="php">
+
==== Template ====
 +
<u>Add this somewhere at top somehwere:</u> <source lang="php">
 
$searchterms = $this->state->get('filter.search');
 
$searchterms = $this->state->get('filter.search');
  
Line 173: Line 174:
 
if (strlen($searchterms)>1) JHtml::_('behavior.highlighter', explode(' ',$searchterms));
 
if (strlen($searchterms)>1) JHtml::_('behavior.highlighter', explode(' ',$searchterms));
 
</source>
 
</source>
And further in your template, enclose the specific fields with the default highlighter finder. (Be careful that your DOM is not breaken by the <br/> tags (like it would wrongly placed between table tags for example).<br/>
+
And further in your template, enclose the specific fields with the default highlighter finder.<br/>
 
<u>Example:</u><source lang="php">
 
<u>Example:</u><source lang="php">
<br id="highlighter-start" />
+
<span id="highlighter-start"></span>
<?php echo $item->name; ?>
+
<table class="adminlist">
<br id="highlighter-end" />
+
...
 +
</table>
 +
<span id="highlighter-end"></span>
 +
</source>
 +
==== CSS ====
 +
If your default admin template doesn't have required css, you should add the class in your component css.
 +
<u>Example in controller:</u><source lang="php">
 +
JHtml::stylesheet('com_peopleactions/admin.css', array(), true);
 +
</source>
 +
<u>In admin.css:</u><source lang="css">
 +
.highlight {  background: none repeat scroll 0 0 #FFFF00; }
 
</source>
 
</source>
  

Revision as of 06:28, 23 November 2012