Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access to api #8

Open
roydukkey opened this issue Dec 14, 2020 · 1 comment
Open

Allow access to api #8

roydukkey opened this issue Dec 14, 2020 · 1 comment

Comments

@roydukkey
Copy link
Contributor

As a user of the component, I would like to be able to download the data as a CSV.

Would it be as simple as changing the following from:

to:

export let api;

Or, is there a better solution?

@roydukkey
Copy link
Contributor Author

Implementing #9 might be a better option for this issue, as it would allow the consumer to write something like this to access the APIs.

<script>
	import AgGrid from "@budibase/svelte-ag-grid";

	let data = [
		{ make: "Toyota", model: "Celica", price: 35000 },
		{ make: "Ford", model: "Mondeo", price: 32000 },
		{ make: "Porsche", model: "Boxter", price: 72000 },
	];

	let columnDefs = [
		{
			headerName: "Make",
			field: "make",
			sortable: true,
			editable: true,
		},
		{ headerName: "Model", field: "model", sortable: true },
		{ headerName: "Price", field: "price", sortable: true },
	];

	let api;

	let options = {
		onGridReady: (params) => {
			api = params.api;
		}
	}

	function download () {
		if (api) {
			api.exportDataAsCsv({
				fileName: 'downloadFileName.csv',
				columnGroups: true
			});
		}
	}

</script>

<style>
	:global(:root) {
		--grid-height: 500px;
	}
</style>

<AgGrid bind:data {columnDefs} {options} />

<button on:click|preventDefault={download}>Download Data</button>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant