Jump to content

Exporting Datatable data in Excel with a different Model function


KSI
 Share

Recommended Posts

Currently I'm using Datatables with pagination. Now I recently added the Datatable.buttons library to use Export to Excel option. Now this functionality works fine but it only exports the first 10 rows of the page I'm currently in due to pagination. Now if I remove the limit in my model class, it will export all the entries which is what I want but it also gets rid of the pagination which decreases my site performance. The following is my current AJAX call code for getting Datatable data:

$('#datatable.table').DataTable({
  searching: true,
  paging: true,
  processing: true,
  serverSide: true,
  bFilter: true,
  dom: 'Bfrtip',
  async: false,
  'columnDefs': [ {
  'targets':[0,1,31,32,33,34,35,36,37], 
  'orderable': false, 
  }],
  buttons: [
          {
            text:"Export to Excel",
              extend: 'excelHtml5',
              exportOptions: {
                  columns: ':visible',
                  modifier:{
                    page:'all'
                  }
              }
          },           
    ],
  ajax: {
    "url": '<?php echo site_url('listings/dtlists'); ?>',
    "type": "POST"
  },
  columns: [{
      data: "title",
      className: "column5"
    },
  ...

Now I've added page:'all' in my modifier, but it still only prints the 1st pagination page. So is there any way that I can use a different model function just for the export button where I can customize the limit manually?

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.