laravel-datatables-editor icon indicating copy to clipboard operation
laravel-datatables-editor copied to clipboard

Export buttons for Datatables editor

Open aaadkins opened this issue 7 years ago • 3 comments

Summary of problem or feature request

How do I add the export buttons to the datatables editor? I have the following code and the Export button shows up but nothing gets displayed when I click on it. Trying to follow this example, https://editor.datatables.net/examples/extensions/exportButtons.html Am I missing something?

Thanks!

public function html()
    {
        return $this->builder()
                    ->columns($this->getColumns())
                    ->minifiedAjax()
                    ->addAction(['width' => '80px'])
                    ->parameters([
                        'dom' => 'Bfrtip',
                        'order' => [1, 'asc'],
                        'select' => [
                            'style' => 'os',
                            'selector' => 'td:first-child',
                        ],
                        'buttons' => [
                            ['extend' => 'create', 'editor' => 'editor'],
                            ['extend' => 'edit', 'editor' => 'editor'],
                            ['extend' => 'remove', 'editor' => 'editor'],
			   ['extend' => 'collection', 'text'=>'Export', 'buttons'=>'excel', 'pdf', 'csv']
                        ]
                    ]);
    }

-->

aaadkins avatar Apr 20 '18 18:04 aaadkins

Jus set the export button?

'buttons' => [
 ['extend' => 'create', 'editor' => 'editor'],
 ['extend' => 'edit', 'editor' => 'editor'],
 ['extend' => 'remove', 'editor' => 'editor'],
 'export'
]

On the other hand, there is a conflict on button name for the script: ['extend' => 'create', 'editor' => 'editor'],. When using the editor, this is the script that I use for server-side js.

(function ($, DataTable) {
    "use strict";

    var _buildUrl = function(dt, action) {
        var url = dt.ajax.url() || '';
        var params = dt.ajax.params();
        params.action = action;

        return url + '?' + $.param(params);
    };

    DataTable.ext.buttons.excel = {
        className: 'buttons-excel',

        text: function (dt) {
            return dt.i18n('buttons.excel', 'Excel');
        },

        action: function (e, dt, button, config) {
            var url = _buildUrl(dt, 'excel');
            window.location = url;
        }
    };

    DataTable.ext.buttons.export = {
        extend: 'collection',

        className: 'buttons-export',

        text: function (dt) {
            return dt.i18n('buttons.export', 'Export') + '&nbsp;<span class="caret"/>';
        },

        buttons: ['csv', 'excel', 'pdf']
    };

    DataTable.ext.buttons.csv = {
        className: 'buttons-csv',

        text: function (dt) {
            return dt.i18n('buttons.csv', 'CSV');
        },

        action: function (e, dt, button, config) {
            var url = _buildUrl(dt, 'csv');
            window.location = url;
        }
    };

    DataTable.ext.buttons.pdf = {
        className: 'buttons-pdf',

        text: function (dt) {
            return dt.i18n('buttons.pdf', 'PDF');
        },

        action: function (e, dt, button, config) {
            var url = _buildUrl(dt, 'pdf');
            window.location = url;
        }
    };

    DataTable.ext.buttons.print = {
        className: 'buttons-print',

        text: function (dt) {
            return  dt.i18n('buttons.print', 'Print');
        },

        action: function (e, dt, button, config) {
            var url = _buildUrl(dt, 'print');
            window.location = url;
        }
    };

    DataTable.ext.buttons.reset = {
        className: 'buttons-reset',

        text: function (dt) {
            return dt.i18n('buttons.reset', 'Reset');
        },

        action: function (e, dt, button, config) {
            dt.search('').draw();
        }
    };

    DataTable.ext.buttons.reload = {
        className: 'buttons-reload',

        text: function (dt) {
            return dt.i18n('buttons.reload', 'Reload');
        },

        action: function (e, dt, button, config) {
            dt.draw(false);
        }
    };

    DataTable.ext.buttons.add = {
        className: 'buttons-add',

        text: function (dt) {
            return dt.i18n('buttons.add', 'New');
        },

        action: function (e, dt, button, config) {
            window.location = window.location.href.replace(/\/+$/, "") + '/create';
        }
    };
})(jQuery, jQuery.fn.dataTable);

Or you can just edit the existing script and change create to add

    DataTable.ext.buttons.add = {
        className: 'buttons-add',

        text: function (dt) {
            return dt.i18n('buttons.add', 'New');
        },

        action: function (e, dt, button, config) {
            window.location = window.location.href.replace(/\/+$/, "") + '/create';
        }
    };

yajra avatar May 05 '18 09:05 yajra

Hi I use:

                'language' => [
                    'url' => asset('js/datatables/json/es.json')
                ],

for translations, but buttons are still in english. How do I set language for all these i18n() texts? Thanks!

dhcmega avatar Sep 27 '18 12:09 dhcmega

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Mar 27 '24 00:03 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Apr 04 '24 00:04 github-actions[bot]