Created
February 9, 2018 13:58
-
-
Save petyosi/0bc1f4119dac9e4015a02d1874c86a64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<ag-grid-vue class="ag-theme-fresh grid" | |
:gridOptions="gridOptions" | |
:rowData="rowData" | |
:rowClicked="onRowClicked" | |
:rowDataChanged="onRowDataChanged"> | |
</ag-grid-vue> | |
</template> | |
<script> | |
import Vue from "vue"; | |
import {AgGridVue} from "ag-grid-vue"; | |
import 'whatwg-fetch' | |
import SliderFilter from './SilderFilter.vue'; | |
export default { | |
name: 'munro-grid', | |
data () { | |
return { | |
gridOptions: null, | |
rowData: null | |
} | |
}, | |
components: { | |
AgGridVue | |
}, | |
methods: { | |
loadRowData() { | |
fetch('/static/munros.json') | |
.then((response) => { | |
return response.json() | |
}) | |
.then((json) => { | |
this.rowData = json; | |
}); | |
}, | |
createColDefs() { | |
return [ | |
{headerName: "Hill Name", field: "hillname", width: 225, suppressSizeToFit: true}, | |
{headerName: "Grid Reference", field: "gr6"}, | |
{ | |
headerName: "Height (m)", | |
field: "height", | |
filterFramework: SliderFilter, | |
filterParams: { | |
min: 900, | |
max: 1500, | |
step: 100, | |
initialValue: 1500 | |
} | |
}, | |
{headerName: "Latitude", field: "latitude"}, | |
{headerName: "Longitude", field: "longitude"}, | |
{headerName: "Climbed?", field: "climbed"} | |
]; | |
}, | |
onRowClicked(params) { | |
this.$emit("munroSelected", params.node.data) | |
}, | |
onRowDataChanged() { | |
Vue.nextTick(() => { | |
this.gridOptions.api.sizeColumnsToFit(); | |
} | |
); | |
} | |
}, | |
created() { | |
this.gridOptions = { | |
enableFilter:true | |
}; | |
this.gridOptions.columnDefs = this.createColDefs(); | |
this.loadRowData(); | |
} | |
} | |
</script> | |
<style scoped> | |
.grid { | |
height: 255px; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment