dudapiotr / ZfTable

*Not supported*ZfTable 3.1. Awesome ZF2 table / grid (and much much more) generator with huge possibilities of decorating and conditioning. Integrated with DataTables, Doctrine 2, Bootstrap 2.0 and 3.0.
http://dudapiotrek.laohost.net/
MIT License
75 stars 59 forks source link

Suggestion to add an optional no results found row when rendering as HTML. #98

Open aNorthernSoul opened 7 years ago

aNorthernSoul commented 7 years ago

It would be nice to have an option to have the renderRowHtml output a row with a configurable message if no results were found. For example, in the renderRowHtml function, you could simply do something like:

` private function renderRowHtml() { $data = $this->getTable()->getData(); $headers = $this->getTable()->getHeaders(); $render = '';

    if ( !sizeof($data) ) {
        return sprintf('<tr %s><td colspan="%s">%s</td></tr>', $this->getAttributes(), sizeof($this->getTable()->getHeaders()), 'There is no data to display.');
    }

    foreach ($data as $rowData) {
        $this->setActualRow($rowData);
        $rowRender = '';

        foreach ($headers as $name => $options) {
            $rowRender .= $this->getTable()->getHeader($name)->getCell()->render('html');
        }

        foreach ($this->decorators as $decorator) {
            $decorator->render('');
        }

        $render .= sprintf('<tr %s>%s</tr>', $this->getAttributes(), $rowRender);
        $this->clearVar();
    }
    return $render;

} `

Ideally the message could be set in the table class extending AbstractTable so that it could be unique to each table but even the above would be handy.