Data Table and Export using Sharepoint REST

Data Table and Export using Sharepoint REST

jktodd007jktodd007 Posts: 8Questions: 2Answers: 0

I have a Data Table that pulls information from a Sharepoint list using REST.
I want to export this list to Excel (reason for using data table is it is not limited by 5000 items)
below is my code but the button is not working.
In the example, it does not show putting a Button HTML in the code so I am not sure if the script creates the button itself.

$(document).ready( function() { $('#example').DataTable( { dom: 'Bfrtip', buttons: [ { extend: 'excelHtml5', customize: function( xlsx ) { var sheet = xlsx.xl.worksheets['sheet1.xml']; $('row c[r^="C"]', sheet).attr( 's', '2' ); } } ] } ); } ); function LoadZipCodes(state) { var ItemVType = document.getElementById("VType").value; var call = $.ajax({ url: "https://mysite/_api/Web/Lists/GetByTitle('SpendPlanRollup')/items?&$filter=(FiscalYear eq '"+state+"')and(Appropriation eq'"+ItemVType+"')&$top=6000", type: "GET", dataType: "json", headers: { Accept: "application/json;odata=verbose" }, }); call.done(function (data,textStatus, jqXHR){ $('#example').dataTable({ "bDestroy": true, "bProcessing": true, "aaData": data.d.results, "oLanguage": { "sSearch": "Filter Records: " }, "aoColumns": [ { "mData": "MDEP" }, { "mData": "State" }, { "mData": "Sub_x0020_Program" }, { "mData": "State_x0020_Priority" }, { "mData": "ARNG_x0020_PM_x0020Priority" }, ] }); }); call.fail(function (jqXHR,textStatus,errorThrown){ alert("Error retrieving Tasks: " + jqXHR.responseText); }); }

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @jktodd007 ,

    If you're not seeing the buttons, the problem is likely that you're not including all the JS or CSS files. The best bet is to look at this page here, and compare your sources with the Javascript and CSS tabs and see if anything is missing,

    Cheers,

    Colin

  • jktodd007jktodd007 Posts: 8Questions: 2Answers: 0

    Ok there was a css class missing now I see the button. However, when I execute the search function to pull results it disappears.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    That's is odd. If you could link to the page or a test case we can take a look. 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.

    Cheers,

    Colin

  • jktodd007jktodd007 Posts: 8Questions: 2Answers: 0

    I got it working it is because I destroy the table and recreate it but I needed to recreate the buttons as well.

This discussion has been closed.