This extension generates csv file output for selected tables on a page, multiple selection is allowed
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]
[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
Total 7 comments
Hi,
Its not working fine when i have pagination. I like to export full table
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.
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.
Thanks for the extension. I had two issues and will give my solutions for both:
see
http://www.yiiframework.com/forum/index.php?/topic/4213-csvout-install-problem/
greetings
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);
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
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:
function exportToCsv() { ... if (cells[k].className.indexOf('{$this->ignoredCol}') === -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.nodeName.toLowerCase()!=='a'){ input.setAttribute('value', cells[k].innerHTML); } else {input.setAttribute('value', cells[k].firstChild.innerHTML); } formCsv.appendChild(input); } ... }
Leave a comment
Please login to leave your comment.