yii2-table-export-widget Allows to export an HTML table in different formats

  1. Installation
  2. Usage
  3. Resources

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.

ButtonTableExport Screenshot

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', // from a grid
        '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
});

Resources

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

2 0
6 followers
0 downloads
Yii Version: 2.0
License: BSD-2-Clause
Category: User Interface
Developed by: Antonio Ramirez
Created on: Sep 1, 2014
Last updated: 9 years ago

Downloads

show all

Related Extensions