KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

How to enable Buttons plugin of DataGrid. #1781

Closed Nicholas Savill opened this topic on on Dec 22, 2020 - 5 comments

Nicholas Savill commented on Dec 22, 2020

I am strugging to get the Buttons plugin of the DataGrid working.

I have added the following properties to my DataTables::create() call:

DataTables::create([
  "plugins" => ["Buttons"],
  "options" => [
    "dom" => 'Bfrtip',
    "buttons" => [
        "copy", "csv", "excel", "pdf", "print"
    ],
  ],
  ...
]);

When I render the report, no buttons are created. However, I get the following messages on the console:

GET http://localhost:8000/koolreport_assets/css/KRDataTables.css net::ERR_ABORTED 404 (Not Found)
registerLink @ VM17166 KoolReport.js:185
(anonymous) @ VM17166 KoolReport.js:145
css @ VM17166 KoolReport.js:144
resources @ VM17166 KoolReport.js:16
init @ VM17166 KoolReport.js:217
(anonymous) @ customeramountowing:401
GET http://localhost:8000/koolreport_assets/js/KRDataTables.js net::ERR_ABORTED 404 (Not Found)
registerScript @ VM17166 KoolReport.js:80
(anonymous) @ VM17166 KoolReport.js:40
js @ VM17166 KoolReport.js:39
(anonymous) @ VM17166 KoolReport.js:37
(anonymous) @ VM17166 KoolReport.js:105
checkScriptsAndCallback @ VM17166 KoolReport.js:102
onScriptLoaded @ VM17166 KoolReport.js:88
load (async)
registerScript @ VM17166 KoolReport.js:78
(anonymous) @ VM17166 KoolReport.js:40
js @ VM17166 KoolReport.js:39
resources @ VM17166 KoolReport.js:12
init @ VM17166 KoolReport.js:217
(anonymous) @ customeramountowing:358

I discovered that if I removed the additional properties from the DataTables::create() call, I still had the same message. So it may be a separate issue, and I wonder if this is the root cause of the Buttons failing to display.

Any help to resolve these issues would be appreciated.

Best wishes Nick

Sebastian Morales commented on Dec 22, 2020

Nicholas, in the latest Datagrid package version there has been an issue with loading DataTables' js and css files in framework like Laravel, Symphony. We are going to release a fix soon. Meanwhile, you could try the following workaround:

https://www.koolreport.com/forum/topics/1759#p9492

Nicholas Savill commented on Dec 22, 2020

Hi Sebastian

I am indeed using Laravel, and the fix you suggested resolved the 404 errors in the console. However, it hasn't made my buttons appear from the plugin. Any ideas?

Thanks as ever Nick

    DataTables::create([
      "dataSource"=>$report->dataStore("unpaidInvoices"),
      "plugins" => ["Buttons"],
      "options" => [
        "dom" => 'Bfrtip',
        "buttons" => [
            "copy", "csv", "excel", "pdf", "print"
        ],
      ],      
      ...

Sebastian Morales commented on Dec 22, 2020

Do you see a script linked to a file "DataTables.buttons.min.js" in your page's html source?

Nicholas Savill commented on Dec 22, 2020

There is reference to this file in KoolReport widget.

    KoolReport.widget.init(
        {"js":["\/koolreport_assets\/417790547\/jquery.min.js",["\/koolreport_assets\/3578238540\/KRDataTables.js","\/koolreport_assets\/3578238540\/datatables.min.js",["\/koolreport_assets\/3578238540\/pagination\/input.js","\/koolreport_assets\/3578238540\/Buttons-1.6.2\/js\/dataTables.buttons.min.js","\/koolreport_assets\/3578238540\/Buttons-1.6.2\/js\/buttons.colVis.min.js","\/koolreport_assets\/3578238540\/Buttons-1.6.2\/js\/buttons.html5.min.js","\/koolreport_assets\/3578238540\/Buttons-1.6.2\/js\/buttons.print.min.js","\/koolreport_assets\/3578238540\/JSZip-2.5.0\/jszip.min.js","\/koolreport_assets\/3578238540\/pdfmake-0.1.36\/pdfmake.min.js",["\/koolreport_assets\/3578238540\/pdfmake-0.1.36\/vfs_fonts.js"],"\/koolreport_assets\/3578238540\/AutoFill-2.3.5\/js\/dataTables.autoFill.min.js","\/koolreport_assets\/3578238540\/ColReorder-1.5.2\/js\/dataTables.colReorder.min.js","\/koolreport_assets\/3578238540\/RowGroup-1.1.2\/js\/dataTables.rowGroup.min.js","\/koolreport_assets\/3578238540\/Select-1.3.1\/js\/dataTables.select.min.js"]]],"css":["\/koolreport_assets\/3578238540\/KRDataTables.css","\/koolreport_assets\/3578238540\/datatables.min.css"]},

One thing I can't see in the widget is anything which seems to correspond to the options.dom or options.buttons properties.

Nicholas Savill commented on Dec 23, 2020

I have resolved the issue. In the DataTables::create() call I had accidentally created two "options" properties. Merging them into a single property resolved the issue.

Before:

    DataTables::create([
      "dataSource"=>$report->dataStore("unpaidInvoices"),
      "plugins" => ["Buttons"],
      "options" => [
        "dom" => 'Bfrtip',
        "buttons" => [
            "copy", "csv", "excel", "pdf", "print"
        ],
      ],      
      "columns"=>[...],
      "options" => [
        "searching"=>true,
        "paging"=>true,
      ],
    ]);

After:

    DataTables::create([
      "dataSource"=>$report->dataStore("unpaidInvoices"),
      "plugins" => ["Buttons"],
      "options" => [
        "dom" => 'Bfrtip',
        "buttons" => [
            "copy", "csv", "excel", "pdf", "print"
        ],
        "searching"=>true,
        "paging"=>true,
      ],      
      "columns"=>[...],
    ]);

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
solved

None