csvout install problem

Another problem installing one extension:

I have installed csvout extensions like this:

1- I copy all the ‘csv’ folder under /protected/extensions

2-I add to my /protected/config/main.php file:

'controllerMap'=>array(


          'csv'=>array(


              'class'=>'application.extensions.csv.CsvController',


              'property1'=>'value1',


              'property2'=>'value2',


              ),


 ),

before the ‘components’=>array(…’ part

3-In the Admin form of my windows i put:

<?php $this->widget(‘application.extensions.csv.csvWidget’, array(

                    'table' =&gt; '.dataGrid',


                    'csvFile' =&gt; ''));


     ?&gt;

4- when i click to export list to CSV i have:

proprieties "CsvController.property1" not define.

c:\projects\yii\framework\YiiBase.php(191)

00179: {

00180: unset($args[0]);

00181: $class=new ReflectionClass($type);

00182: // Note: ReflectionClass::newInstanceArgs() is available for PHP 5.1.3+

00183: // $object=$class->newInstanceArgs($args);

00184: $object=call_user_func_array(array($class,‘newInstance’),$args);

00185: }

00186: }

00187: else

00188: $object=new $type;

00189:

00190: foreach($config as $key=>$value)

00191: $object->$key=$value;

00192:

00193: return $object;

00194: }

I try to:

In main.php change:

‘controllerMap’=>array(

          'csv'=&gt;array(


              'class'=&gt;'application.extensions.csv.CsvController',


              'property1'=&gt;'value1',


              'property2'=&gt;'value2',


              ),


 ),

to:

‘controllerMap’=>array(

          'csv'=&gt;array(


              'class'=&gt;'application.extensions.csv.CsvController',


         'table' =&gt; '.dataGrid',


                    'csvFile' =&gt; '',


              ),


 ),

but i have a similar problem "proprieties "CsvController.table" not define."

Any idea? Some people use csvout?

Thanks

Darkfly, csvout documentation contains ‘property1’=>‘value1’, ‘property2’=>‘value2’ only as example of setting other properties for CsvController class. And ‘property1’ / ‘property2’ are not real properties.

For simplest case you need to add to /protected/config/main.php:




'controllerMap'=>array(

              'csv'=>array(

                  'class'=>'application.extensions.csv.CsvController',

                  //here you can set other properties for CsvController object  

                  ),

     ),



And add to view:




$this->widget('application.extensions.csv.csvWidget', 

   //here you can set other properties for CsvWidget object

);



Ok thanks for the help, is exporting now.

But i have a problem, when i click in export bouton, i have one file called "data.csv" but in this export file, i have:

"" <a href="/nova/index.php?r=terceiros/admin&amp;sort=id">Id</a>;<a href="/nova/index.php?r=terceiros/admin&amp;sort=tipo">Tipo</a>;<a href="/nova/index.php?r=terceiros/admin&amp;sort=nome">Nome</a>;<a href="/nova/index.php?r=terceiros/admin&amp;sort=contacto">Contacto</a>;<a href="/nova/index.php?r=terceiros/admin&amp;sort=email">Email</a>;<a href="/nova/index.php?r=terceiros/admin&amp;sort=nif">Nif</a>;<a href="/nova/index.php?r=terceiros/admin&amp;sort=nib">Nib</a>;<a href="/nova/index.php?r=terceiros/admin&amp;sort=agencia_id">Agência</a>;Actions

<a href="/nova/index.php?r=terceiros/show&amp;id=1">1</a>;1;Limpa tudo lda;;;;;Agência1;<center>

&lt;a href=&quot;/nova/index.php?r=terceiros/update&amp;amp;id=1&quot;&gt;&lt;img src=&quot;images/edit2.png&quot; alt=&quot;Modificar&quot; border=&quot;0&quot; height=&quot;25&quot; width=&quot;25&quot;&gt;&lt;/a&gt;

"

this is the HTML code i have in the TALBE (<table class="dataGrid" id="table">), not the coluns export like i expect…

i use this code in the view page:

<?php $this->widget(‘application.extensions.csv.csvWidget’, array(

                    'table' =&gt; '.dataGrid',


                    'csvFile' =&gt; ''));


     ?&gt;

before the table (i try after too)…

Why i have the export in html format and not csv?

Sorry,i don’t see the review in the extension page, i have to change the widget function to not output the A tag.

I change the fonction with:

   if(cells[k].firstChild.nodeName.toLowerCase()&#33;=='a'){


    input.setAttribute('value', cells[k].innerHTML);


} else {


    input.setAttribute('value', cells[k].firstChild.innerHTML);


}

but with this code, nothing append when i click in the csv export button.

I try the orignal code of function,and change only:

input.setAttribute(‘value’, cells[k].innerHTML);

to

input.setAttribute(‘value’, cells[k].firstChild.innerHTML);

and nothing append when i click in button

if i change back to

input.setAttribute(‘value’, cells[k].innerHTML);

the csv open, but with <a html code…

The part "firstChild" seems to be the cause of the problem… but why?

Try this code:




//check if cell contains a link

if((!cells[k].firstChild) || (cells[k].firstChild.nodeName.toLowerCase()!=='a')){

    input.setAttribute('value', cells[k].innerHTML);

} else {

    input.setAttribute('value', cells[k].firstChild.innerHTML);

}



I attached also my (modified) version of csv extension: 288

csv.zip
.

This version can export all table data regardless of pagination (current version exports only visible data).

To export all data you need to disable pagination in your controller code if "format" parameter is given:




    /**

     * Manages all models.

     */

    public function actionAdmin()

    {

        $criteria=new CDbCriteria;


        ...


        $format = Yii::app()->request->getParam('format');


        $pages=new CPagination(User::model()->count($criteria));

        $pages->pageSize= self::PAGE_SIZE;


        //if format is set - no pagination

        if (!isset($format)) {

            $pages->applyLimit($criteria);

        }


        $sort=new ExtSort('User');

        $sort->defaultOrder = "lname";

        $sort->applyOrder($criteria);


        $models=User::model()->findAll($criteria);


        $params = array(

                'models'=>$models,

                'pages'=>$pages,

                'sort'=>$sort,

                ...,

                'format'=>isset($format)?$format:''

        );

      

        if (Yii::app()->request->isAjaxRequest) {

            $this->renderPartial('adminList', $params);

        } else {

            $this->render('admin', $params);

        }

    }



Thanks Seb is working now with this code:

//check if cell contains a link

if((!cells[k].firstChild) || (cells[k].firstChild.nodeName.toLowerCase()!==‘a’)){

input.setAttribute('value', cells[k].innerHTML); 

} else {

input.setAttribute('value', cells[k].firstChild.innerHTML); 

}

i try your csv.zip too, and is working, i have only one problem to include the JQuery UI, because of the "dialog" you use to the export message

i have added in the widget code:

$this->widget(‘application.extensions.jui.EJqueryUiInclude’, array(‘theme’=>‘humanity’));

after that all is working.

Many Thanks for the help.

what’s wrong with me. i just had downloaded csv.zip above, and then:

  1. extract them into extentions directory

  2. added this script into config/main.php :




'controllerMap'=>array(

    'csv'=>array(

        'class'=>'application.extensions.csv.CsvController',

	'table' => '.dataGrid',

	'csvFile' => ''),

),



  1. and then added this script into views/user/admin :

<?php $this->widget('application.extensions.csv.csvWidget', array(

'table' => '.dataGrid',

'csvFile' => ''));

?>

  1. and also modified my userController :

public function actionAdmin()

{

	$this->processAdminCommand();


	$criteria=new CDbCriteria;

	 

	$filters = new CDataFilter(user::model());

        $filters->addFilter(new CFilterSearch('userFieldsSearch', 'Filter :'));

        $filters->applyCriteria($criteria);


        $pages=new CPagination(user::model()->count($criteria));

        $pages->pageSize=self::PAGE_SIZE;

		

	$format = Yii::app()->request->getParam('format');

		

        //if format is set - no pagination

        if (!isset($format)) {

            $pages->applyLimit($criteria);

        }

		

	$sort=new CSort('user');

        $sort->defaultOrder = "username";

        $sort->applyOrder($criteria);


	/* 

        i have no Extsort here, is this custom sort ?

	$sort=new ExtSort('user');

	$sort->applyOrder($criteria);

	*/


        $models=user::model()->findAll($criteria);

		

	$params = array(

                'models'=>$models,

                'pages'=>$pages,

                'sort'=>$sort,

                'filters'=>$filters,

                'format'=>isset($format)?$format:''

        );

      

        if (Yii::app()->request->isAjaxRequest) {

            $this->renderPartial('adminList', $params);

        } else {

            $this->render('admin', $params);

        }

        

	}

is there somethings wrong ? it did’t response anything when i clicked export button.

thanks before.

You have a error in main.php:

For simplest case you need to add to /protected/config/main.php:

‘controllerMap’=>array(

          'csv'=&gt;array( 


              'class'=&gt;'application.extensions.csv.CsvController', 


              //here you can set other properties for CsvController object   


              ), 


 ),

youv don’t need to put :

‘table’ => ‘.dataGrid’,

    'csvFile' =&gt; ''),

in main.php.

and read the post from begining, if you have over problems.

thanks Darkfly, but it still not working for me.

i had changed my controllerMap in main.php to :


'controllerMap'=>array(

		'csv'=>array(

		'class'=>'application.extensions.csv.CsvController',

		//here you can set other properties for CsvController object

		),

	),

i think map controller just mapping the real controler directory webapp/protected/controller to our path custom right?. so i don’t need controllerMap if i just copied CsvController.php into webapp/protected/controller.

i guest my problem just on the JQuery. here is my source code from firefox selection source:


 <a onclick="return exportToCsv();" href="#"><img src="/gts2009/assets/8c4f6571/csv.gif" class="img_link" title="export"></a>

<script type="text/javascript">

/*<![CDATA[*/

                

                var formCsv;


                function makeCsvData()

                {

                    formCsv = $('#csvExportForm').get(0);                    

                    arrayEl = $('#csvExportData .dataGrid').get();

                    for (var i=0; i<arrayEl.length; i++) {

                        rows = arrayEl[i].rows;

                        for (var j=0; j<rows.length; j++){

                            if (rows[j].className.indexOf('filterRow') === -1) {

                                cells = rows[j].cells;

                                for (var k=0; k<cells.length; k++){

                                    if (cells[k].className.indexOf('actionCol') === -1) {

                                        var input = document.createElement('input');

                                        input.setAttribute('type', 'hidden');

                                        input.setAttribute('name', 'tCells['+i+']['+j+']['+k+']');

                                        //check if cell contains a link

                                        if((!cells[k].firstChild) || (cells[k].firstChild.nodeName.toLowerCase()!=='a')){

                                            input.setAttribute('value', cells[k].innerHTML);

                                        } else {

                                            input.setAttribute('value', cells[k].firstChild.innerHTML);

                                        }

                                        formCsv.appendChild(input);

                                    }

                                }

                            }

                        }

                    }

                    input = document.createElement('input');

                    input.setAttribute('type', 'hidden');

                    input.setAttribute('name', 'csvFile');

                    input.setAttribute('value', 'data.csv');

                    formCsv.appendChild(input);

                }


                function exportToCsv()

                {

                    $('<div id="csvExportData" style="visibility:hidden"></>').appendTo('body');

                    $('<div id="exportDialogContent" style="margin:0 40px;display:block;"></div>').appendTo('body');

                    $('<form id="csvExportForm" method="POST" action="/gts2009/index.php/csv/index.html"></form>').appendTo('body');

                    

                    $('#exportDialogContent').html('<span><img src="/css/loading.gif" style="vertical-align:middle;"> Exporting data ...</span>');

                    

                    $('#exportDialogContent').dialog(

                    {

                        title: 'Export to CSV',

                        dialogClass: 'export-dialog',                        

                        autoOpen: false,                        

                        position: 'center',                        

                        resizable: false,

                        height:46,

                        minHeight:40


                    }

                    );

                    $('.export-dialog .ui-dialog-titlebar').hide();

                    $('.export-dialog').css('opacity', '0.5');

                    $('#exportDialogContent').dialog('open');


                    

                    jQuery.ajax(

                            {'type':'POST','url':window.location.href,'cache':false,

                                'data':'format=csv',

                                'success':function(html) {

                                    jQuery('#csvExportData').html(html);

                                    makeCsvData();

                                    formCsv.submit();

                                    $('#exportDialogContent').dialog('destroy');

                                    jQuery('#csvExportData').remove();

                                    jQuery('#exportDialogContent').remove();

                                    jQuery('#csvExportForm').html('');

                                    return false;

                                },

                                error: function (XMLHttpRequest, textStatus, errorThrown) {

                                    $('#exportDialogContent').html('Can not export data, status: ' + textStatus);

                                    $('.export-dialog .ui-dialog-titlebar').show();

                                    $('.export-dialog').css('opacity', '1');

                                    $('#exportDialogContent').dialog('option', 'buttons', { 'Close': function() { $('#exportDialogContent').dialog('destroy'); } });

                                }

                            }

                    );                                               

                    

                    return false;

                }

            

/*]]>*/

</script>

it’s rather hard to debug on web apps. :D

i’m trying to build a new clear yii webapp.

  1. setting db connection.

  2. created model and crud. using yiic.

  3. extract csv to extentions dir

  4. modified main.php

  5. added widget into admin view

but it still not working.

the only good things i saw the "Exporting data …" on my screen when i clicked export button.

but nothings data to exported.

it makes me so confused. :(

Hi, pegel.linuxs

Do you still have this problem? Can you attach sources of your demo application?

Also try to make export while having FireBug console open - you should see whether export request is successfully processed on server side or not.

Another way to find our what is wrong is to use php debugger (I am using netbeans + xdebug).

Regards, Seb

an error occured using firebug was like this


$("#exportDialogContent").dialog is not a function

exportToCsv()index.ph...ser/admin (line 87)

function onclick(event) { return exportToCsv(); }(click clientX=303, clientY=161)index.ph...ent/seq/1 (line 2)

[Break on this error] minHeight:40\n

here you are :

An error was because my version of csvout was dependent on jQuery Dialog (for ajax "loading" indicator). Now I changed csvout code and removed that dependency, 322

csv.zip
).

I also attached working version of your demo app, 323

csv_app.zip
.

thank’s a lot seb, it works fine for me now.

i would change the header for exporting to word/excel apps.

i had made it in simple way.

header("Content-type: application/msword"); (ms word)

header("Content-type: application/vns.ms-excel"); (ms excel)

Hi everyone, extension works just great :) Do you have any ideas how to support colspan in table (as rowspan is too dificult). I tried to modify makeCsvData where form input is created, but results are horrible ;)

Simple empty cells after, when td has colspan would be enough…

i have yhe solution for export file to csv… thanks full for your example… btw are u from indonesia??