I'm trying to Export filtered data from SharePoint list to excel by Add a Web part >> Media And Content >> Content Editor. It works fine on the main site list. The problem I'm facing is that it is not working when I create a subsite and in that subsite I have a list to export. It is only working there in an edit mode as soon as I save the edit page it no longer exporting.
Below is my code: which was uploaded to the Site Assets Gallery as .txtfile
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
<script>
function fnExcelReport() {
$('.ms-listviewtable').css({
'border-collapse': 'collapse',
'border': '1px solid #ddd'
});
$('.ms-listviewtable tr td').css({
'border': '1px solid #ddd'
});
var tab_text = $('.ms-listviewtable')[0].outerHTML;
debugger;
$(tab_text).find("tr td:first-child").remove();
tab_text = tab_text.replace(/<A[^>]*>|<\/A>/g, "");
tab_text = tab_text.replace(/<img[^>]*>/gi, "");
tab_text = tab_text.replace(/<input[^>]*>|<\/input>/gi, "");
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))
{
txtArea1.document.open("txt/html", "replace");
txtArea1.document.write(tab_text);
txtArea1.document.close();
txtArea1.focus();
sa = txtArea1.document.execCommand("SaveAs", true, "ActionPoints.xls");
} else
tab_text = excelExportHtml(tab_text, true)
sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
return (sa);
}
function excelExportHtml(table, includeCss) {
var html = "<html><head>";
html += "</head><body>" + table + "</body></html>";
return html;
}
</script>
<body>
<input type="button" value="Export To Excel" onclick="fnExcelReport();" />
<iframe id="txtArea1"></iframe>
</body>
Any guidance or suggestions on how to make this work would be highly appreciated.