1. The 3.8 code for Fabrik is now available on github, in the 'master' branch. If you are familiar with updating Fabrik from github, we would appreciate it if you could test this code on J! 3.8 for us. Once we have some feedback, we'll build a 3.8 release.

Alphabetical Filter

Mar 30, 2016
Alphabetical Filter

  • Fabrik 3.1 (top)

    list-tabs.png
    Edit your list and under the layout tab you will see a Tabs section.
    Select a field you wish to use as the tab filter, and enter the maximum number of tabs to show. Then press save.

    For Fabrik 3.0 or less(top)

    Follow the instructions below to create an alphabetical list of links that filter a table's data by a column first letter.

    Make a custom table template: Copy the folder components/com_fabrik/views/tmpl/default and rename it to default_alphafilter.

    Then edit default_alphafilter/default.php and after:
    PHP:
    if ($this->showFilters) {
        echo $this->loadTemplate('filter');
    }?>
    add (Actually, you may add this before or after.. Pretty Much anywhere!!!)
    PHP:
    <?php
        $element = 'element_test___test';
        $url = 'http://'.$_SERVER['HTTP_HOST'].'/FULL/PATH';
        $letters = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
        foreach($letters as $l){
            echo "<a href='{$url}?resetfilters=1&".$element."[value]=$l%25&".$element."[condition]=LIKE'>$l</a>";
        }
    ?>
    This will print out a row of links filtering on each letter. The only thing you will need to change is
    PHP:
    $element = 'element_test___test';
    Replace 'element_test' with your table name and 'test' with the element name.

    Also.. to make this work, you will need to replace FULLPATH. This works best with SEF. Then use the url generated for this value.

    In case you would like to use this template for more than one list.. The following might help you out. The following assumes the field you are filtering is the same for all lists you will use. To make this work, you have to use menu items that have an alias as the name of your list. SEF is required for this to work.
    PHP:
    <ul class="alphafilter">
    <?php
        // strip out all stuff and get only the part we need
        $uri_parts = explode('?', $_SERVER['REQUEST_URI'], 2);
        $url = $uri_parts[0];
        $pathparts = explode('/',$url);
        $this_list = array_pop($pathparts);
        //if popped value is null, there was a trailing slash.. so pop again.
        if($this_list == NULL || $this_list == ''){
            $this_list = array_pop($pathparts);          
        }
        $element = 'fab_'.$this_list.'___name';
        $letters = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
        foreach($letters as $l){
            echo "<li><a href='{$url}?resetfilters=1&".$element."[value]=$l%25&".$element."[condition]=LIKE'>$l</a></li>";
        }
    ?>
        <li><a href="<?php echo ($url); ?>">Show ALL</a></li>
    </ul>
    If you have the field in the filter, that you are using for the index, LastName for instance, you will see, after clicking on a letter that the filter for the LastName field will have that letter plus the % char. the % in sql is for WILDCARD.

    You can remove the % buy doing a substr on the $filter. On the alpha index, you probably will only have this one filter. The following will not work if you are using more than one filter. It will remove the last char from every filter. This would probably be undesirable. This change is made in the default_filter.php template file.
    PHP:
    <?php echo substr($filter->element,0,1);?>
    Note: If you would like to still FILTER the results, then you must set resetfilters=1 to 0 or just take it out.

    ----------------------------------------

    An alternative to this is to create a calculated field with the first character of the field you want to select by putting the following in the Calculation box:
    PHP:
    return substr("{placeholder}",0,1);
    You can then set this as a default group-by box for your list and you will then get the ability to open or close each group.

    Note: This needs to load all rows in your table, so you will need to set the number of rows displayed to >= number of rows in the table, and it is not really scalable for more than several hundred rows.
  • Loading...