I am unable to add a excel export button

I am unable to add a excel export button

AgathopAlexAgathopAlex Posts: 7Questions: 1Answers: 0
edited July 14 in Free community support

i have added the code to add download button on my datatable but it is not showing what could i be missing.

see snippet

 tables: {
     instructions: $('#returnsTable').DataTable({
         buttons:"excel",
         responsive: true,
         bFilter: false,
         processing: true,
         language: {
             loadingRecords: "Please wait - loading...",
             processing: '<div></div><div></div><div></div><div></div><div></div>'
         },
         serverSide: false,

Replies

  • allanallan Posts: 64,744Questions: 1Answers: 10,713 Site admin

    Hi,

    Thanks for your question. As noted in the forum rules, please post a link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Allan

  • kthorngrenkthorngren Posts: 22,159Questions: 26Answers: 5,101

    Based on your code snippet it doesn't look like you told Datatables where to place teh buttons using the layout option. See these docs for more details. Also see this example.

    Kevin

  • AgathopAlexAgathopAlex Posts: 7Questions: 1Answers: 0

    i have tried the positioning of the button no luck.

  • allanallan Posts: 64,744Questions: 1Answers: 10,713 Site admin

    Can you show us your latest code please, or even better a link to the page showing the issue, as required in the forum rules?

    Allan

  • AgathopAlexAgathopAlex Posts: 7Questions: 1Answers: 0
    edited July 16

    i cannot send a link as it is locked behind user authentication,
    here is the new code

      instructions: $('#returnsTable').DataTable({
          responsive: true,
          bFilter: false,
          processing: true,
          language: {
              loadingRecords: "Please wait - loading...",
              processing: '<div></div><div></div><div></div><div></div><div></div>'
          },
          serverSide: false,
          paging: true,
          jQueryUI: false,
          autoWidth: true,
          //scrollY: '325px',
          scrollY: '480px',
          //scrollY: '65%',
          //scrollY: GetScrollHeight(),
          scrollX: true,
          scrollCollapse: true,
          deferRender: true,
          aoData: [{}],
          hideEmptyCols: true,
          columns: [
              { data: "accountno", title: "Account No", autoWidth: true, orderable: true },
              { data: "account_name", title: "Account Name", autoWidth: true, orderable: true },
              {
                  data: 'cons_no',
                  title: 'Consignment No',
                  autoWidth: true,
                  render: function (value, type, data, info) {
                      return '   <div class="input-group">' +
                          '       <div class="input-group-btn">' +
                          '           <button type="button" class="btn btn-info form-control returnOpen" data-action="details">' +
                          '           <span>' + value + '</span>' +
                          '           </button>' +
                          '       </div>' +
                          '   </div>';
                  },
                  orderable: true
              },
              { data: "ret_no", title: "Return No", autoWidth: true, orderable: true },
              { data: "org_cons", title: "Original Waybill Number", autoWidth: true, orderable: true },
              { data: "ret_serial", title: "Serial", autoWidth: true, visible: false },
              { data: "returntype", title: "Type", autoWidth: true, orderable: true },
              {
                  data: "ret_date",
                  title: "Date",
                  autoWidth: true,
                  render: function (data) {
                      var date = new Date(data);
                      var month = date.getMonth() + 1;
                      return date.getFullYear() + "-" + (month.toString().length > 1 ? month : "0" + month) + "-" + (date.getDate().toString().length > 1 ? date.getDate() : "0" + date.getDate());
                  },
                  type: "datetime",
                  orderable: true
              },
              { data: "sender_name", title: "Sender", autoWidth: true, orderable: true },
              { data: "consignee_name", title: "Consignee", autoWidth: true, orderable: true },
              { data: "rr_code", title: "Reason Code", autoWidth: true, visible: false },
              { data: "rr_name", title: "Reason", autoWidth: true },
              { data: "require_new_address", title: "Require New Address", autoWidth: true },
              { data: "new_address_name", title: "New Consignee", autoWidth: true },
              { data: "process_as", title: "Process As", autoWidth: true },
              { data: "isprocessed", title: "Processed Status", autoWidth: true, orderable: true, searchable: true }
          ],
          columnDefs: [
              {
                  targets: '_all',
                  width: '4%',
                  searchable: false,
                  orderable: false,
                  className: 'text-center'
              }],
          layout: {
              topStart: {
                  buttons: [ 'excel']
              }
          },
          createdRow: function (a, b, c) {
              var options = {
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 64,744Questions: 1Answers: 10,713 Site admin

    Assuming you have Buttons, the HTML 5 export buttons and JSZip loaded on your page, then the above should cause the export button to show.

    Perhaps you could create a temporary login and PM it to me, or use JSFiddle or similar to create a test case? I'm sure you can appreciate that it is very hard to debug something that is working in the demos but being told it isn't working in a case which I can't see.

    Allan

Sign In or Register to comment.