2amigos/yii2-table-export-widget

The table export widget for the Yii framework

Installs: 797

Dependents: 0

Suggesters: 0

Stars: 13

Watchers: 12

Forks: 10

Open Issues: 4

Language:JavaScript

Type:yii2-extension

0.1.0 2014-09-01 22:06 UTC

README

Latest Stable Version Total Downloads Latest Unstable Version License

ButtonTableExport widget is a wrapper for the 2amigOS! TableExport jQuery plugin. It provides a number of options to export an HTML table in different formats.

The current supported formats are:

  • json
  • csv
  • html
  • excel
  • pdf

The plugin can also be used separately, that is, by using ButtonTableExportTable and registering its assets. By doing it, you could configure any click'able HTMLElement on your page.

The widget extends yii\bootstrap\DropdownButton, therefore, you can use all its properties.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require "2amigos/yii2-table-export-widget" "*"

or add

"2amigos/yii2-table-export-widget" : "*"

to the require section of your application's composer.json file.

Usage

Using data-uri method. Please, check http://caniuse.com/#feat=datauri to find out about browser support for this method.

use dosamigos\tableexport\ButtonTableExport;

echo ButtonTableExport::widget([
     [
        'label' => 'Export Table Grid',
        'selector' => '#my-grid-id > table',
        'split' => true,
        'exportClientOptions' => [
            'ignoredColumns' => [0, 7], // lets ignore some columns
            'useDataUri' => true,
        ]
    ]
]);

Using TableExportAction - the most reliable option:

// On your controller
use dosamigos\tableexport\ButtonTableExport;

// ...
public function actions()
{
    return [
        // ...
        'download' => [
            'class' => TableExportAction::className()
        ]
        // ...
    ];
}

// ...

// On your view
use dosamigos\tableexport\ButtonTableExport;

<?= ButtonTableExport::widget(
    [
        'label' => 'Export Table',
        'selector' => '#tableId', // any jQuery selector
        'exportClientOptions' => [
            'ignoredColumns' => [0, 7],
            'useDataUri' => false,
            'url' => \yii\helpers\Url::to('controller/download')
        ]
    ]
);?>

Using it manually

<?php
// On your view
use dosamigos\tableexport\ButtonTableExportAsset;

ButtonTableExportAsset::register($this);
?>

<a id="linkId" >Export Table as Xml</a>
// On your javascript file
$('#linkId').tableExport({
    type: "xml",
    useDataUri: true
});

2amigOS!
Web development has never been so fun!
www.2amigos.us