list: skip first row and use it as headers

Status
Not open for further replies.

susannanam

Member
hello all,

i wonder if that is somehow possible: i have some "basic tables" with columns named col1, col2, col3, etc.

every table has a row called "header" in col1 and that row contains headers for the list. meaning the list should pick the headers out of this row instead using the column names. all other rows shall be used as data.

does someone have an idea if that is possible and how i could do that?

thanks
susanne
 
I think it could be done with a custom list template.

It depends on what you want to do with your list:

If it's just display without any Fabrik functions like grouping, sorting, pagination, ajax, list plugings... it should
be not so complicated (maybe just CSS to hide the original header and style the first row "header like")
 
I think it could be done with a custom list template.

It depends on what you want to do with your list:

If it's just display without any Fabrik functions like grouping, sorting, pagination, ajax, list plugings... it should
be not so complicated (maybe just CSS to hide the original header and style the first row "header like")

thanks troester for your idea :) i try to keep it simple and have everything done before creating the list so that i should be able to avoid fabrik functions. can you maybe give me an idea how i can hide the original header (without deleting the functionality) and apply that look to my first row? thanks.
 
"Quick and dirty" custom CSS:
Code:
#listform_$c .fabrikDataContainer thead {display:none}
#listform_$c .fabrikDataContainer tbody tr:nth-child(2) {color:red;font-weight:bold;background:grey}
which will hide the header and style the 2nd <tr> (the 1st one contains the empty data message).
But this is only working if you have no pagination, no filters, no elements linked to details etc.

Otherwise you have to create really a custom template which replaces header labels with 1st row information...
 
"Quick and dirty" custom CSS:
Code:
#listform_$c .fabrikDataContainer thead {display:none}
#listform_$c .fabrikDataContainer tbody tr:nth-child(2) {color:red;font-weight:bold;background:grey}
which will hide the header and style the 2nd <tr> (the 1st one contains the empty data message).
But this is only working if you have no pagination, no filters, no elements linked to details etc.

Otherwise you have to create really a custom template which replaces header labels with 1st row information...

thanks so much troester, i will try that :)
 
thanks so much troester, i will try that :)

hi troester,

finally i could try as the table is ready... i amended the custom css accordingly but it throws out the error: 500 Layout default_row not found. do you have an idea what the problem is?

thanks for your time
susanne
 
Well, that's because you seem to have copied the content of both a form and a list template into your custom template folder. :(

Anyway, we just finished our Skype session, we fixed that snafu, and I wound up doing this, and the other stuff you needed from this thread:

http://www.fabrikar.com/forums/inde...blish-or-toggle-columns-based-on-entry.39622/

... in the default.php for your custom list template.

NOTE that my code is very "quick and dirty", and is specific to that list. I didn't realize you had several lists you needed to do this to. So, you'll need to create a template for each list, look in default.php, starting around line 117, you'll see this code I added:

Code:
                if ($this->_row->data->sh2m8_summary1___order_field == '1') {
                    //var_dump($this->_row->data);
                    $cells = JArrayHelper::fromObject($this->_row->data);
                    $this->skip_cells = array();
                    foreach ($cells as $ckey => $cvalue) {
                        if (preg_match('/^sh2m8_summary1___course\d+$/', $ckey) && empty($cvalue)) {
                            $this->skip_cells[$ckey]++;
                        }
                    }
                    //var_dump($this->skip_cells);
                    continue;
                }

So for each list you create this template for, change where I've hard wired the element names, which is in two places, and change the sh2m8_summary1 to whatever the name should be for that list.

Oh, and remember you need to add layout=custom_layout_name in the {fabrik ...} plugin string in your article(s), with whatever the template name is (instead of custom_layout_name) to make sure it overrides the default. For some reason, I forget why, when the list is generated from a content plugin, it ignores what the setting is on the main List settings, you have to set custom templates in the plugin.

-- hugh
 
If I get time tonight, I'll go back and make that code better, so you won't need to copy and edit the template for each list, but right now I have to go take care of some other posts for other folk. I'll update this thread if I manage to find the time.

But at least you have a workaround for now.

-- hugh
 
friendly bump.... as i said Hugh, the hiding of the columns works and yes, i an work with the "workaround" and make a template for each of the 7 cases. but currently it is hiding the first row instead of the header...

susanne
 
OK, I did some more work on this, it should now:

Be using the first row of data as the titles.

Be generic, so you can use the same custom template for all of your course summaries, no need to copy and edit it.

-- hugh
 
thanks a lot Hugh, it works perfectly fine now :) here is the new default.php in case someone else will have the same requirement :)

Code:
<?php
 
// No direct access
 
defined('_JEXEC') or die('Restricted access');
 
//echo "TABLE:" . $this->table->db_table_name;
 
$pageClass = $this->params->get('pageclass_sfx', '');
 
if ($pageClass !== '') :
 
echo '<div class="' . $pageClass . '">';
 
endif;
 
if ($this->tablePicker != '') : ?>
 
<div style="text-align:right"><?php echo FText::_('COM_FABRIK_LIST') ?>: <?php echo $this->tablePicker; ?></div>
 
<?php
 
endif;
 
if ($this->params->get('show_page_heading')) :
 
echo '<h1>' . $this->params->get('page_heading') . '</h1>';
 
endif;
 
if ($this->params->get('show-title', 1)) : ?>
 
<div class="page-header">
 
<h1><?php echo $this->table->label;?></h1>
 
</div>
 
<?php
 
endif;
 
// Intro outside of form to allow for other lists/forms to be injected.
 
echo $this->table->intro;
 
?>
 
<form class="fabrikForm form-search" action="<?php echo $this->table->action;?>" method="post" id="<?php echo $this->formid;?>" name="fabrikList">
 
<?php
 
if ($this->hasButtons):
 
echo $this->loadTemplate('buttons');
 
endif;
 
if ($this->showFilters && $this->bootShowFilters) :
 
echo $this->loadTemplate('filter');
 
endif;
 
//for some really ODD reason loading the headings template inside the group
 
//template causes an error as $this->_path['template'] doesnt cotain the correct
 
// path to this template - go figure!
 
$headingsHtml = $this->loadTemplate('headings');
 
echo $this->loadTemplate('tabs');
 
?>
 
<div class="fabrikDataContainer">
 
<?php foreach ($this->pluginBeforeList as $c) :
 
echo $c;
 
endforeach;
 
?>
 
<table class="<?php echo $this->list->class;?>" id="list_<?php echo $this->table->renderid;?>" >
 
<thead>
 
<tr>
 
<?php
 
$titles = JArrayHelper::fromObject($this->rows[0][0]->data);
 
foreach ($titles as $title_key => $title) {
 
if (strstr($title_key,'_raw') || strstr($title_key,'___order_field') || !strstr($title_key, $this->table->db_table_name . '___'))
 
{
 
continue;
 
}
 
if (!empty($title))
 
{
 
echo "<th>" . $title . "</th>";
 
}
 
}
 
echo "<th></th>";
 
?>
 
</tr>
 
<?php
 
// echo $headingsHtml
 
?>
 
</thead>
 
<tfoot>
 
<tr class="fabrik___heading">
 
<td colspan="<?php echo count($this->headings);?>">
 
<?php echo $this->nav;?>
 
</td>
 
</tr>
 
</tfoot>
 
<?php
 
if ($this->isGrouped && empty($this->rows)) :
 
?>
 
<tbody style="<?php echo $this->emptyStyle?>">
 
<tr>
 
<td class="groupdataMsg emptyDataMessage" style="<?php echo $this->emptyStyle?>" colspan="<?php echo count($this->headings)?>">
 
<div class="emptyDataMessage" style="<?php echo $this->emptyStyle?>">
 
<?php echo $this->emptyDataMessage; ?>
 
</div>
 
</td>
 
</tr>
 
</tbody>
 
<?php
 
endif;
 
$gCounter = 0;
 
foreach ($this->rows as $groupedby => $group) :
 
if ($this->isGrouped) : ?>
 
<tbody>
 
<tr class="fabrik_groupheading info">
 
<td colspan="<?php echo $this->colCount;?>">
 
<?php if ($this->emptyDataMessage != '') : ?>
 
<a href="#" class="toggle">
 
<?php else: ?>
 
<a href="#" class="toggle fabrikTip" title="<?php echo $this->emptyDataMessage?>" opts='{trigger: "hover"}'>
 
<?php endif;?>
 
<?php echo FabrikHelperHTML::image('arrow-down.png', 'list', $this->tmpl, FText::_('COM_FABRIK_TOGGLE'));?>
 
<span class="groupTitle">
 
<?php echo $this->grouptemplates[$groupedby]; ?> ( <?php echo count($group)?> )
 
</span>
 
</a>
 
</td>
 
</tr>
 
</tbody>
 
<?php endif ?>
 
<tbody class="fabrik_groupdata">
 
<tr style="<?php echo $this->emptyStyle?>">
 
<td class="groupdataMsg emptyDataMessage" style="<?php echo $this->emptyStyle?>" colspan="<?php echo count($this->headings)?>">
 
<div class="emptyDataMessage" style="<?php echo $this->emptyStyle?>">
 
<?php echo $this->emptyDataMessage; ?>
 
</div>
 
</td>
 
</tr>
 
<?php
 
foreach ($group as $this->_row) :
 
$order_field = $this->table->db_table_name . '___order_field';
 
if ($this->_row->data->$order_field == '1') {
 
//var_dump($this->_row->data);
 
$cells = JArrayHelper::fromObject($this->_row->data);
 
$this->skip_cells = array();
 
foreach ($cells as $ckey => $cvalue) {
 
$re = '/^' . $this->table->db_table_name . '___course\d+$/';
 
if (preg_match($re, $ckey) && empty($cvalue)) {
 
$this->skip_cells[$ckey]++;
 
}
 
}
 
//var_dump($this->skip_cells);
 
continue;
 
}
 
echo $this->loadTemplate('row');
 
endforeach
 
?>
 
<?php if ($this->hasCalculations) : ?>
 
<tr class="fabrik_calculations">
 
<?php
 
foreach ($this->calculations as $cal) :
 
echo "<td>";
 
echo array_key_exists($groupedby, $cal->grouped) ? $cal->grouped[$groupedby] : $cal->calc;
 
echo "</td>";
 
endforeach;
 
?>
 
</tr>
 
<?php endif ?>
 
</tbody>
 
<?php
 
$gCounter++;
 
endforeach?>
 
</table>
 
<?php print_r($this->hiddenFields);?>
 
</div>
 
</form>
 
<?php
 
echo $this->table->outro;
 
if ($pageClass !== '') :
 
echo '</div>';
 
endif;
 
echo "<style>";
 
foreach ($this->skip_cells as $skey => $sval) {
 
echo "." . $skey . " {\n";
 
echo " display: none !important\n";
 
echo "}\n";
 
echo "\n";
 
}
 
echo "</style>\n";
 
?>
 
When posting PHP code, best to use the little "insert code" button that looks like {} that, select PHP as the type of code, and paste it in there.

Or at least wrap code tags around it. :)

(Put the word code in square brackets before the code, and /code in square brackets after the code)

-- hugh
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top