美文网首页
dcat admin 添加自定义操作按钮

dcat admin 添加自定义操作按钮

作者: 阳光天天耀 | 来源:发表于2021-03-23 18:15 被阅读0次

    $grid->actions(function (Grid\Displayers\Actions $actions) {

                    $actions->append( new DownloadAction());

                });

    DownloadAction.php文件的实现:

    namespace App\Admin\Extensions;

    use Dcat\Admin\Grid\RowAction;

    class DownloadAction extends RowAction

    {

        /**

    * 返回字段标题

    *

        * @return string

    */

        public function title()

    {

            return '下载表格';

    }

           /**

    * 添加JS

    *

        * @return string

    */

        protected function script()

    {

            return <<

            $('.download-btn').on('click', function () {

                console.log();

                let url = $(this).data('excel');

                var x = new XMLHttpRequest();

                x.open("GET", url, true);

                x.responseType= 'blob';

                x.onload=function(e) {

                var url = window.URL.createObjectURL(x.response)

                var a = document.createElement('a');

                a.href = url;

                a.download= "表格标题";

                a.click()

    };

                x.send();

    });

            JS;

    }

        public function html()

    {

            $this->setHtmlAttribute(['data-excel' => $this->row->excel_url,'class'=>'download-btn fa fa-download']);

            return parent::html();

    }

    }

    相关文章

      网友评论

          本文标题:dcat admin 添加自定义操作按钮

          本文链接:https://www.haomeiwen.com/subject/iqafhltx.html