json-export-excel icon indicating copy to clipboard operation
json-export-excel copied to clipboard

Fetch data on click event

Open korolei opened this issue 8 years ago • 6 comments

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 avatar Sep 13 '16 20:09 korolei

@korolei thank you for feedback. I will review it

trantrunghieu0809 avatar Sep 15 '16 01:09 trantrunghieu0809

yes. This will be a nice addition. I am also trying to modify the code and see if I can do it.

abhimishra18 avatar Sep 15 '16 22:09 abhimishra18

@abhimishra18 , great if have the help of you

trantrunghieu0809 avatar Sep 16 '16 07:09 trantrunghieu0809

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']); }); });

romeonuen avatar Dec 17 '16 04:12 romeonuen

@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.

korolei avatar Dec 20 '16 14:12 korolei

I achieved this my adding ng-mouseover="fetchResults()" This is just a work around which can help if someone stuck at this point.

nitheshcse avatar Mar 15 '17 22:03 nitheshcse