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
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
Ok there was a css class missing now I see the button. However, when I execute the search function to pull results it disappears.
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
I got it working it is because I destroy the table and recreate it but I needed to recreate the buttons as well.