0

I have multiple filters on the page which gives me results, My objective is to provide an export link somewhere on the page which should have url with Id(s) as the parameter, thru which user can export filtered data, I don't want to use jQuery datatable.

Please provide suggestions.

  • Please elaborate a little bit, I think I did understand but I need to be sure. – Salah Jan 8 at 8:30
  • export link be like, someurl?itemid=1,2,3, when user click on it, it should return data of item 1, 2 and 3 from sharepoint list as excel form. – Rishi Jagati Jan 8 at 9:08
  • OOTB it is not possible. You need to use custom coding with third party login(open source are available). – Ganesh Sanap Jan 8 at 10:02
  • I can understand, that OOTB will not work here, do you have any JSOM related solution? – Rishi Jagati Jan 8 at 10:06
0

One embarrassing solution would be to update current URL and then use native SharePoint Export to Excel button. Open your items list and filter with one ID, you may notice that URL looks like: yourPage.aspx#InplviewHashYouCurrentView=FilterFields1%3DID-FilterValues1%3DXXX%253B%2523YYY. You would then update it within window.location.href by appending desired IDs.

A better and viable solution is a more robust out-of-the-box JS development. Let us suppose that we have our list items context (through ctx.ListData.Row objects array) and a function called getIDs that retrieves our desired IDs. We will use tableexport JS library to export data to Excel; which needs an HTML table element for export. We need to build our HTML table with our items filtered by our getIDs.

var IDs = getIDs(); // Array of int
var items = ctx.ListData.Row; // Array of objects
for(var i=0;i<items.length;i++) {
    tableStr = '<table id="placeholder_table_export">';
    if(IDs.indexOf(items[i]['ID']) != -1) { // Item needs to be retrieved
        tableStr += '<tr><td>'+ items[i]['ID'] +'</td><td>'+ items[i]['Title'] +'</td></tr>';
    }
    tableStr += '</table>';
}

Next, once the above table is appended to your HTML, you would use TableExport to export that created table.

var excelExporter = new TableExport(placeholderTableExport.getElementById('#placeholder_table_export'), {
    formats: ['xlsx'], 
    filename: filename, 
    trimWhitespace: false, 
    exportButtons: false
});

var exportedData = excelExporter.getExportData();
exportedData = exportedData[Object.keys(exportedData)[0]]['xlsx'];
excelExporter.export2file(exportedData.data, exportedData.mimeType,
exportedData.filename, exportedData.fileExtension);

(TableExport is easier to use, but since we need to init Excel export immediately, we have to use this workaround.)

I hope you get the idea.

  • tableexport is like datatable export, well seems there is no alternative left apart from this. I am already binding the data in a different way of HTML, due to this I have to bind data two times, one with my HTML and one for to export table this will hamper performance. let me try, will get back to you. thanks – Rishi Jagati Jan 9 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.