This extension generates csv file output for selected tables on a page, multiple selection is allowed
Documentation ¶
Requirements ¶
- Yii 1.0.5
Installation ¶
Copy all the 'csv' catalogue under /protected/extensions
Register controller 'CsvController' in /protected/config/main.php:
[php]
'controllerMap'=>array(
'csv'=>array(
'class'=>'application.extensions.csv.CsvController',
'property1'=>'value1',
'property2'=>'value2',
),
...........other controllers (if exist)
),
[php]
Usage ¶
- Add button(s) to your view page (several times, if needed - as many as you wish!):
[php]
<?php $this->widget('application.extensions.csv.csvWidget', array(
'property1'=>'value1',
'property2'=>'value2'));
?>
[php]
where possible properties with their default values are:
'table' => '.dataGrid' string selector (understanding by jQuery $()-function) of the table(s) to be output, by default it's a 'table' with class='dataGrid' (selection result may be not single!)
'csvFile' => '' string csv file name (if '', it will be 'data.csv' by default)
'ignoredRow' => 'filterRow' string class name for the rows 'tr' which should be omitted in the csv output
'ignoredCol' => 'actionCol' string class name for the cells 'td', 'th' to be omitted in the csv output
'htmlOptions' => array() array htmlOptions array - standard for Yii
Change Log ¶
July 5, 2009 ¶
- Initial release.
two issues
Thanks for the extension. I had two issues and will give my solutions for both:
A. At the very top of the actionIndex method I added:
B. Then, inside of the "foreach($table as $row)" section I replaced the code to look like this:
Hope that helps someone.
forgiveness for confusing
see
http://www.yiiframework.com/forum/index.php?/topic/4213-csvout-install-problem/
greetings
correction
var dato=cells|k|.innerHTML;
var index_a2= dato.lastIndexOf("< / a >");
if (index_a2!=-1) {
var index_a1= dato.substring(0,index_a2).lastIndexOf(">")+1;
var dato_link= dato.substring(index_a1,index_a2);
input.setAttribute('value', dato_link);
}
else
input.setAttribute('value', cells|k|.innerHTML);
title link for sort
hi seb
your solution not work for me
mi solution :
var dato=cells[k].innerHTML;
var index_a2= dato.lastIndexOf(\"\");
if (index_a2!=-1) {
var index_a1= dato.substring(0,index_a2).lastIndexOf(\">\")+1;
var dato_link= dato.substring(index_a1,index_a2);
input.setAttribute('value', dato_link);
}
else
input.setAttribute('value', cells[k].innerHTML);
i'm using PHPExcel
if you are interested, ask me
greetings
Fix: links are exported as
Column headers often contains links for sorting.
Now this links exported as < a href ... >Text< /a>.
To fix this we need to change exportToCsv() JS function in csvWidget.php:
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.nodeName.toLowerCase()!=='a'){ input.setAttribute('value', cells\[k\].innerHTML); } else { input.setAttribute('value', cells\[k\].firstChild.innerHTML); } formCsv.appendChild(input);
}
...
}
Using csvout with Yii 1.1.6
Hello,
I added the changes suggested by seb and luoshiben into the package.
Also, I noticed that once the results were filtered through an Ajax call, the changes were not reflected in the CSV export. For this, the existing form (id=csvExportForm) has to removed.
\$(\"#csvExportForm\").remove();
This line goes before the formCsv initialisation. With this, there is also no need for the firstTime variable and its check. Thus, we get correct CSV export after each search operation.
Tested in IE8, Firefox 3.6 and Chrome 10.
If pagination
Hi,
Its not working fine when i have pagination. I like to export full table
Strip HTML from header rows (and all other rows).
If HTML is screwing up your CSV, change line 106 from:
input.setAttribute('value', cells[k].innerHTML);
to:
input.setAttribute('value', jQuery(cells[k].innerHTML).text());
Great extension!
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.