[SOLVED] Template and ajaxifier

csim

Member
Hello,

I've created a new view of list. In that view, I've added css class in my table rows.
I've set up ajax in fabrik parameters. So when I launch search, page is not reloaded but only datas in the table.
It's ok but I'm losing my css class.
Do I have forgotten something ?

Best Regards
 
In com_fabrik/views/list/tmpl, I've added a new directory "consultations", files (duplicated from original default) and modifyed default_row.php :
PHP:
<?php
/**
* Fabrik List Template: Default Row
*
* @package    Joomla
* @subpackage  Fabrik
* @copyright  Copyright (C) 2005 Fabrik. All rights reserved.
* @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
 
// No direct access
defined('_JEXEC') or die;
//var_dump(@$this->_row);
?>
<tr id="<?php echo $this->_row->id;?>" class="<?php echo $this->_row->class;?><?php if (@$this->_row->data->consultations___type_consultation == "Activit? publique") {echo " publique";} else {echo " liberale";} ?>">
    <?php foreach ($this->headings as $heading => $label) {
        $style = empty($this->cellClass[$heading]['style']) ? '' : 'style="'.$this->cellClass[$heading]['style'].'"';
        ?>
        <td class="<?php echo $this->cellClass[$heading]['class']?>" <?php echo $style?>>
            <?php
            if ($heading == "consultations___service")
            {
                echo "<a href='index.php?option=com_content&view=article&id=86&Itemid=188&id_service=".@$this->_row->data->consultations___service_raw."' target='_blank'>".@$this->_row->data->$heading."</a>";
            }
            else
            {
                echo @$this->_row->data->$heading;
            } ?>
        </td>
    <?php }?>
</tr>

I've also defined this template as user template in parameters.

Best Regards
 
Hmmmm. I think the problem there is that when using AJAX on the list for navigation, only the initial page load is run through the template. Once the page is loaded, and the list is modified through an AJAX event (like navigating to a new page), only the row's data is returned by the AJAX call, as JSON data, and our JavaScript inserts the data in to the pre-existing DOM structure for the table.

I think you'll have to do this with custom JavaScript, to add and remove classes on the row on the fly. Or not use AJAX. Which is your preference?

-- hugh
 
Actually, it just occurred to me that we have a built in way of handling this, and it's compatible with AJAX lists.

Under "List view settings" for your type_consultation element, in the "List settings" tab, is an option "Use as row class". Set this to "Yes".

Fabrik will then automatically add the value of this element on each row as an additional class name for the row. The name will be "sanitized", so it only consists of alphanumeric characters, and we'll replace any non alphanumerics with a -, so you'll have to inspect the page after enabling this to see the exact class name you'll need to specify to match that accented string in your element. But once you add a class of that name, it should work, with no further action.

So, for example, if you have an element called "color", and the data in that element is either 'class_red', 'class_green' or 'class_blue', and you set that element as "Use as row class", you could then add 3 classes to your custom CSS ...

.class_red {
color: red;
}

.class_green {
color: green;
}

.class_blue {
color: blue;
}

... and your table rows would get colored accordingly.

The only other wrinkle is classes cannot start with a number, so if your data starts with a number, I believe we prepend the element name to the class name we give that row. But just inspecting the page will tell you what the class names needs to be to match any given data.


-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top