Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82053

Datatables Plugin excel button only exporting hardcoded row data

$
0
0

I am creating a table in a view for a asp.net MVC project. The table template itself is already set up in the view (hardcoded) and i populate the table via javascript using json data from ajax. The table is populating the way I want it too though when I use the Datatable excel button it creates the table in excel but there is no data just the column names.

For reference I am using the example at https://datatables.net/extensions/buttons/examples/html5/simple.html

I have all the dependencies listed in the above link. I harcoded one row into the table and that works when I export the table to excel but not my dynamic data from my script.

I have tried putting the jquery excel button creation code in different parts of my script and that has not work (as you will see in my code) It is only working when i hardcoded a row in the table, not with dynamic data being created and put in the table

`

Event Name Start Date End Date Peoplesoft_ID First Name Last Name Workday_ID District Name District Code Donation Date Amount Recurring Periods Gift
Easter Event Hardcoded Test Hardcoded Test Hardcoded Test Hardcoded Test Hardcoded Test Hardcoded Test Hardcoded Test Hardcoded Test Hardcoded Test Hardcoded Test Hardcoded Test Hardcoded Test
function loadFunction() { var value_id = $('#myhidden').val(); alert(value_id); $.ajax({ type: 'POST', dataType: 'json', contentType: 'application/json; charset=utf-8', url: '/Admin/ShowEventJSON', data: '{ value_id:' + JSON.stringify(value_id) + '}', success: function (data) { createReport(data) }, error: function () { alert('ajax request error') } }); } //$('#example').DataTable({ // dom: 'Bbfrtip', // buttons: [ // 'copy' // ] //}); //$(document).ready(function () { // $('#tableReport').DataTable({ // dom: 'Bbfrtip', // buttons: [ // 'excelHtml5', // ] // }); //}); //Function to populate table function createReport(data) { var myObj = JSON.parse(data); var table = document.getElementById("tableReport"); for (var i in myObj) { var row = document.createElement('tr'); var valuesArray = Object.values(myObj[i]); for (var v in valuesArray) { var cell = document.createElement('td'); var cellValue = document.createTextNode(valuesArray[v]); cell.appendChild(cellValue); row.appendChild(cell); } table.appendChild(row); } $(document).ready(function () { $('#tableReport').DataTable({ dom: 'Bbfrtip', buttons: [ 'excelHtml5', ] }); }); }

`


Viewing all articles
Browse latest Browse all 82053

Trending Articles