Guest User

Untitled

a guest
Feb 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. <template>
  2. <ag-grid-vue class="ag-theme-fresh grid"
  3. :gridOptions="gridOptions"
  4. :rowData="rowData"
  5. :rowDataChanged="onRowDataChanged">
  6. </ag-grid-vue>
  7. </template>
  8. <script>
  9. import Vue from "vue";
  10. import {AgGridVue} from "ag-grid-vue";
  11. import 'whatwg-fetch'
  12. export default {
  13. name: 'munro-grid',
  14. data () {
  15. return {
  16. gridOptions: null,
  17. rowData: null
  18. }
  19. },
  20. components: {
  21. AgGridVue
  22. },
  23. methods: {
  24. loadRowData() {
  25. fetch('/static/munros.json')
  26. .then((response) => {
  27. return response.json()
  28. })
  29. .then((json) => {
  30. this.rowData = json;
  31. });
  32. },
  33. createColDefs() {
  34. return [
  35. {headerName: "Hill Name", field: "hillname", width: 225, suppressSizeToFit: true},
  36. {headerName: "Grid Reference", field: "gr6"},
  37. {headerName: "Height (m)", field: "height"},
  38. {headerName: "Latitude", field: "latitude"},
  39. {headerName: "Longitude", field: "longitude"},
  40. {headerName: "Climbed?", field: "climbed"}
  41. ];
  42. },
  43. onRowDataChanged() {
  44. Vue.nextTick(() => {
  45. this.gridOptions.api.sizeColumnsToFit();
  46. }
  47. );
  48. }
  49. },
  50. created() {
  51. this.gridOptions = {};
  52. this.gridOptions.columnDefs = this.createColDefs();
  53. this.loadRowData();
  54. }
  55. }
  56. </script>
  57. <style scoped>
  58. .grid {
  59. height: 255px;
  60. }
  61. </style>
Add Comment
Please, Sign In to add comment