GridView - how to extend


I’m new to Yii. I’ve read some tutorials and both books from PacktPub - Yii documentation is excellent.

I’d like to ask you for guidiance how to extend GridView to meet following goals:

  1. New GridView should have toolbar with icons which exports the underlaying data to csv, xls, pdf (I know how to make csv, xls or pdf from the data in database - that’s not the question)

  2. The common usage will be: one advanced filter/search/criteria form on the page and then several GridViews displaying different data but all are using the same user input from common filter/search/criteria form.

  3. Some of the underlying SQL queries for GridViews from ad 2) are slow so I’d like to load data for new GridView completly using ajax. When the page is returned it displays just the headers of the GridViews and loading message. Then data for all GridViews are loaded in parallel. So faster GridViews would not wait for slower GridViews even when slower GridViews are preceeding faster ones on the page.

Is there any extension solving this issue? What is the best approach to extend GridView in this way? Or is complete rewrite needed?

Maybe something like what is outlined in "Creating reusable controllers" from Yii Application Development Cookbook can be used. Create reusable controller which returns JSON, than create new GridView widget which consumes JSON. But this sounds like complete rewrite with little reuse of great features CGridView has now.

What do you think is the best way?




class MyGridView extends CGridView



then add your own template to display new buttonbar

instead of creating controllers create reusable actions to export to csv, pdf etc


thanks for your suggestion how to solve point 1! As I’m newbie to Yii, I’m not sure I completely understand your proposal.

As I understand it I should create several reusable actions e.g. CsvAction, XlsAction, PdfAction all extends CActions. And then add it to all controllers where I use my MyGridView.

Is it possible to add my reusable actions to controllers auto-magically or do I have to do it manually by overloading CController->actions() in controllers where I want to use MyGridView?

When there are more MyGridViews on the page what is the best to pass it’s ID (or whatever) to the action?

Thanks a lot,


I think an export-to-csv button should call your myGridViewController with the appropriate action

otherwise you get a controller instance with myGridView->owner and call runAction() with an export-to-csv-action

Where to get a free ico maker?

I have the same issue with you.

I have the code exporting PDF and EXCEL ready, but I don’t know how to bind events in the extended gridview class.

Can we have a talk?