
Zitat von
automatix1311
Gibt es so eine vorgefertigte Lösung (so was wie JHTMLTable) für Joomla?
In der Version 1.5 noch nicht. Bei der 1.6 ist zumindest schonmal eine JHTML 'form' dabei.
Ich habe mir auch eine eigene JHTML Klasse dazu erstellt.
PHP-Code:
class JHTMLJDHTML extends JHTML
{
/* JD! table
*************/
function table($name,$rows,$head=null,$foot=null,$attribs=null)
{
if (!isset($name) || !isset($rows) ) return false;
$table = JHTMLJDHTML::tableStart($name,$attribs);
if ( isset($head->cell) ) :
$HeadRowAttr = (isset($head->RowAttr)) ? $head->RowAttr : null;
$table .= JHTMLJDHTML::thead($head->cell,$HeadRowAttr);
endif;
if ( isset($foot->cell) ) :
$FootRowAttr = (isset($foot->RowAttrs)) ? $foot->RowAttr : null;
$table .= JHTMLJDHTML::tfoot($foot->cell,$FootRowAttr);
endif;
$table .= JHTMLJDHTML::tbody($rows);
$table .= JHTMLJDHTML::tableEnd();
return $table;
}
function tableStart($name=null,$attribs=null)
{
if ( is_array($attribs)&& !empty($attribs['id']) ) :
$id = ' id="'.$attribs['id'].'"';
unset($attribs['id']);
else :
$id = ' id="'.$name.'"';
endif;
$attribs = is_array($attribs) ? ' '.JArrayHelper::toString($attribs) : ' '.$attribs;
return '<table'.$id.$attribs.'>';
}
function tableEnd()
{
return '</table>';
}
function thead($cells,$attribs=null)
{
$attribs = is_array($attribs) ? ' '.JArrayHelper::toString($attribs) : ' '.$attribs;
$row = '<thead>
<tr'.$attribs.'>';
foreach ($cells as $cell) :
$cellAttribs = (isset($cell->attribs)) ? $cell->attribs : null;
$row .= JHTMLJDHTML::tcell($cell->html,$cellAttribs,'th');
endforeach;
$row .= ' </tr>
</thead>';
return $row;
}
function tfoot($cells,$attribs=null)
{
$attribs = is_array($attribs) ? ' '.JArrayHelper::toString($attribs) : ' '.$attribs;
$row = '<tfoot>
<tr'.$attribs.'>';
foreach ($cells as $cell) :
$cellAttribs = (isset($cell->attribs)) ? $cell->attribs : null;
$row .= JHTMLJDHTML::tcell($cell->html,$cellAttribs);
endforeach;
$row .= ' </tr>
</tfoot>';
return $row;
}
function tbody($rows=null,$attribs=null)
{
$attribs = is_array($attribs) ? ' '.JArrayHelper::toString($attribs) : ' '.$attribs;
$body = '<tbody'.$attribs.'>';
foreach ($rows as $row) :
$body .= JHTMLJDHTML::trow($row,$row->RowAttr);
endforeach;
$body .= '</tbody>';
return $body;
}
function trow($cells=null,$attribs=null)
{
$attribs = is_array($attribs) ? ' '.JArrayHelper::toString($attribs) : ' '.$attribs;
$row = '<tr'.$attribs.'>';
foreach ($cells->cell as $cell) :
$cellAttribs = (isset($cell->attribs)) ? $cell->attribs : null;
$row .= JHTMLJDHTML::tcell($cell->html,$cellAttribs);
endforeach;
$row .= '</tr>';
return $row;
}
function tcell($html=null, $attribs=null, $type=null)
{
if (!$type) $type = 'td';
$attribs = is_array($attribs) ? ' '.JArrayHelper::toString($attribs) : ' '.$attribs;
$cell = '<'.$type.''.$attribs.'>'.$html.'</'.$type.'>';
return $cell;
}
In eine Datei speichern und diese Datei vor dem benutzen mit
PHP-Code:
JHTML::addIncludePath(JPATH.DS.'pfad'.DS.'zur'.DS.'datei');
im System registrieren und denn kann es auch schon losgehen.
PHP-Code:
$head->cell['name']->html = JText::_('Name'); // th in thead-> tr
$rows[1]->cell['name']->html = 'Inhalt Zeile 1'; // td in tbody-> tr
$rows[2]->cell['name']->html = 'Inhalt Zeile 2'; // usw.
// Ausgabe Tabelle mit Überschrift (thead)
echo JHTML::_('jdhtml.table', 'name_of_table', $rows, $head);
// edit:
Natürlich kann man auch Attribute, mehrere Spalten, eine Fusszeile (tfoot) etc festlegen.
Ist halt nur nen Beispiel gewesen. Bei Interesse erfolgt hier auch eine ausfühliche Erklärung!
Lesezeichen