Search code examples
phpsortingyiifiltercgridview

Customizing/extending CGridView widget YII


I'm pretty familiar with the CGridView filter and it's a very customizable stuff. But the life isn't perfect and I need to change the, almost completley the layout of the cgridview. (the features will be the same [filtering,sorting]).

So how should I start this "customisation", how can I extend the look of the CGridView?

FYI I need something like this enter image description here


Solution

  • It's easy if you open up the class of CGridView you will see on line 449:

    public function renderItems()
    {
        if($this->dataProvider->getItemCount()>0 || $this->showTableOnEmpty)
        {
            echo "<table class=\"{$this->itemsCssClass}\">\n";
            $this->renderTableHeader();
            ob_start();
            $this->renderTableBody();
            $body=ob_get_clean();
            $this->renderTableFooter();
            echo $body; // TFOOT must appear before TBODY according to the standard.
            echo "</table>";
        }
        else
            $this->renderEmptyText();
    }
    

    you basically need to extend the class, put it in a folder that you can access it in extensions, and override methods in this function