Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

saadaan's avatar

Datatables with Yajra - EXPORT HTML5 EXCEL is not working

Hi,

I am trying to use Yajra plugin for using datatables on Laravel. Everything else is working fine, however the HTML5 EXPORT is only downloading the first set of table results which is displayed on the page only (first 10 in the example below). It is not downloading the whole table. Here is my code:

    <script type="text/javascript">

      //Data Tables
      $(document).ready(function () {
        $('#example').DataTable({
          processing: true,
          serverSide: true,
          iDisplayLength: 10,
          aaSorting: [['0', 'desc']],
          dom: 'Bfrtip',
          buttons: [
                { extend: 'excelHtml5', text: 'Download' }
          ],
          ajax:{
                url: "viewalldata",
          },
          columns:[
         {
            data: 'student_id',
            name: 'student_id'
         }
        ],
        });
      });

    </script>

If anyone can help, I would be much obliged.

Thanks, Saad

0 likes
9 replies
saadaan's avatar
    public function viewalldata(Request $request)
    {
       return datatables()->of(Students::orderBy('id', 'DESC')->get())->make(true);
    }

guybrush_threepwood's avatar

From the Datatables official FAQ:

A. Buttons is a client-side process, so it can only export the data available at the client-side. When server-side processing is enabled, the full data set is not held on the client-side, so only the visible data can be exported. You can either: 1. Use a server-side process to create the files to download (recommended) or 2. Disable server-side processing.

guybrush_threepwood's avatar

If you're using Yajra Datatables I'd recommend using the server side Service approach. It works fine for me.

saadaan's avatar

If I remove B, the DOWNLOAD button doesn't show up.

From your second comment, I understood the concept of using yajra button. Can you help me land onto the exact tutorial on that? Many thanks!

saadaan's avatar

Yes, I am using server side approach. How to use download buttons in that system, if i disable default HTML5 buttons of native datatables?

saadaan's avatar

Yes, this does NOT work well for big datasets with Laravel. So to enable server-side processing, the plugin is Yajra datatables. I am trying to program export buttons in yajra.

Please or to participate in this conversation.