Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8388649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:31:03+00:00 2026-06-09T18:31:03+00:00

I am trying to export cgridview data (current search results) to a CSV by

  • 0

I am trying to export cgridview data (current search results) to a CSV by using the excelview extension, by clicking a button.

However, I am not getting the filtered data in my CSV; instead, I’m getting all the records in the model.

This is my controller action I am calling:

    public function actionExcel()
{
    $model = new PackagingMetric('search'); 
    $this->widget('application.extensions.EExcelView', array( 
            'dataProvider'=> $model->search(), 
            'grid_mode'=>'export', 
            'exportType'=>'Excel5', 
            'filename'=>'report', 
            )); 
}

Would anyone know how to resolve this issue, or where my error is ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:31:05+00:00Added an answer on June 9, 2026 at 6:31 pm

    You don’t have any search criteria there. Usually you do it like this:

    $model = new PackagingMetric('search');
    $model->attributes = $_POST['PackagingMetric']; // this would be the model associated with the search form
    $model->search();
    

    I don’t see anything in your code that takes values from user input, so you should use your search form somehow. Of course, you could have default values in your model, but I don’t think that’s the case.

    Edit:

    I looked a bit more into the source code of the extension you are using. It seems that the export buttons are actually standard <a href=''></a> links that send you to a page that’s supposed to output the Excel sheet. However, because the actual filter data is not transmitted to that page, there’s no way to apply those filters server-side.

    Since this is the intended behavior of the extension, there’s no elegant way to solve it, but there are messy ways.

    A first option would be to tweak the extension yourself, but this will break compatibility with future versions. Another way is to use Javascript to send your data where you need it. In the view file where you are displaying the gridview, you should wrap the widget in a form element or in an ActiveForm with all validation disabled. Then you need to place the following piece of Javascript code somewhere on the page:

    var $excelForm = $( '#your_form_id' );
    $( '.summary a', $excelForm ).click( function() {
        $excelForm.attr( 'action', this.href ).submit();
        return false;
    });
    

    This will submit the form to the address specified by the export link. Because the form wraps the widget, it will contain the input elements that filter your results, so you will have access to the user-entered filters on the server. You can use the code I originally posted to pick up the data from there.

    Note: I am using the default class name for the div that contains the export buttons, which is .summary. If you are using a different class, you should change the respective JS code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to export data to a csv file. It should contain a header
I'm trying to export XML data from a web page to a spreadsheet using
I am trying to export a list of table to comma-separated value(CSV) .but not
I am trying to export a data.frame to a csv with utf-8 encoding. I
I'm trying to export data from SQL Server into CSV format. I have a
I am trying to export the following data in the query from ms sql
I'm trying to export about 300k records to XLS using a DelayedJob in heroku
I have been trying to export a mysql table with INTO OUTFILE to CSV
Trying to export NSTextView data to an RTF doc. My old code, mainly filename
I am trying to export Group membership - following is the script , however

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.