json-export-excel
json-export-excel copied to clipboard
Fetch data on click event
Hi, The way your plugin works is that data should be available when user click on the button. Is there any way to call web api service first, when user clicks on a button?
Thanks, Igor
@korolei thank you for feedback. I will review it
yes. This will be a nice addition. I am also trying to modify the code and see if I can do it.
@abhimishra18 , great if have the help of you
u can pass a function(call server with data callback) to data and change click event code like this:
element.bind('click', function() { scope.data(function (dt) { var bodyData = _bodyData(dt); var strData = _convertToExcel(bodyData); var blob = new Blob([strData], {type: "text/plain;charset=utf-8"}); return saveAs(blob, [scope.filename + '.csv']); }); });
@romeo-nxp callback function would not work, as it is asynchronous call and by the time data get back, _convertToExcel function will be called already. I solved this issue with using two buttons: 'Fetch Data' & ' Export Data'. Only one button visible at a time and user has to click twice to get data into Excel.
I achieved this my adding ng-mouseover="fetchResults()" This is just a work around which can help if someone stuck at this point.