Data Export on click of Custom Button

I want to download all the data present in datatable to be exported as csv on click of a custom button.
To load data to datatable, i’m using api so I want all data returned by api to be exported not just visible section

Solved. Used GET Method to get the data on click of custom button (from api).