Skip to content

Allows the exportation of an HTML table to a different formats

Notifications You must be signed in to change notification settings

kinwing/yii2-table-export-widget

 
 

Repository files navigation

Table Export Widget for Yii2

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

About

Allows the exportation of an HTML table to a different formats

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 62.7%
  • PHP 28.5%
  • CSS 8.8%