vue集成ag-grid框架

VUE2集成方案

1.创建vue项目
2.添加依赖

npm install --save ag-grid-community ag-grid-vue vue-property-decorator@^8.0.0

3.在src/App.vue添加样式

<style lang="scss">
  @import "~ag-grid-community/dist/styles/ag-grid.css";
  @import "~ag-grid-community/dist/styles/ag-theme-alpine.css";
</style>

4.在vue文件添加模板代码

<template>
    <ag-grid-vue style="width: 500px; height: 500px;"
        class="ag-theme-alpine"
        :columnDefs="columnDefs"
        :rowData="rowData">
    </ag-grid-vue>
</template>
<script>
import { AgGridVue } from "ag-grid-vue";

export default {
  name: "App",
  data() {
    return {
      columnDefs: null,
      rowData: null,
    };
  },
  components: {
    AgGridVue,
  },
  beforeMount() {
    this.columnDefs = [
      { field: "make" },
      { field: "model" },
      { field: "price" },
    ];

    this.rowData = [
      { make: "Toyota", model: "Celica", price: 35000 },
      { make: "Ford", model: "Mondeo", price: 32000 },
      { make: "Porsche", model: "Boxter", price: 72000 },
    ];
  },
};
</script>
<style lang="scss">
   @import "~ag-grid-community/dist/styles/ag-grid.css";
   @import "~ag-grid-community/dist/styles/ag-theme-alpine.css";
</style>

集成侧边栏

<div style="height: 100%">
    <ag-grid-vue
        style="width: 100%; height: 100%;"
        class="ag-theme-alpine"
        id="myGrid"
        :columnDefs="columnDefs"
        @grid-ready="onGridReady"
        :defaultColDef="defaultColDef"
        :sideBar="sideBar"
        :rowData="rowData"></ag-grid-vue>
</div>

data(){
	return {
		defaultColDef: {
	      flex: 1,
	      minWidth: 100,
	      enableValue: true,
	      enableRowGroup: true,
	      enablePivot: true,
	      sortable: true,
	      filter: true,
	    },
	    sideBar: true,
	    columnDefs:[],
	    rowData: null,
	}
}

VUE3集成方案

1.创建vue项目
2.添加依赖

npm install ag-grid-vue3 ag-grid-community vue-class-component@next

3.在src/App.vue添加样式

<style lang="scss">
  @import "~ag-grid-community/dist/styles/ag-grid.css";
  @import "~ag-grid-community/dist/styles/ag-theme-alpine.css";
</style>

4.在vue文件添加模板代码

<template>
  <ag-grid-vue
    style="width: 500px; height: 200px"
    class="ag-theme-alpine"
    :columnDefs="columnDefs"
    :rowData="rowData"
  >
  </ag-grid-vue>
</template>

<script>
import "ag-grid-community/dist/styles/ag-grid.css";
import "ag-grid-community/dist/styles/ag-theme-alpine.css";
import { AgGridVue } from "ag-grid-vue3";

export default {
  name: "App",
  components: {
    AgGridVue,
  },
  setup() {
    return {
      columnDefs: [
        { headerName: "Make", field: "make" },
        { headerName: "Model", field: "model" },
        { headerName: "Price", field: "price" },
      ],
      rowData: [
        { make: "Toyota", model: "Celica", price: 35000 },
        { make: "Ford", model: "Mondeo", price: 32000 },
        { make: "Porsche", model: "Boxter", price: 72000 },
      ],
    };
  },
};
</script>

ag-grid破解

//破解ag-grid
import 'ag-grid-enterprise';
import {LicenseManager} from 'ag-grid-enterprise'
LicenseManager.prototype.validateLicense = function(){
    return true
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
ag-Grid Vue 是一个用于构建灵活的、高性能的数据表格和数据网格的 Vue 组件库。它是与 Vue 框架集成ag-Grid 社区版。使用 ag-Grid Vue,您可以轻松地在 Vue 应用程序中创建功能丰富的数据表格和网格,并利用 ag-Grid 提供的丰富功能和性能优势。 要在 Vue 应用程序中使用 ag-Grid Vue,您需要先安装 ag-Grid Vue 包。您可以使用 npm 或 yarn 进行安装: ```bash npm install --save ag-grid-vue # 或 yarn add ag-grid-vue ``` 安装完成后,您可以在 Vue 组件中引入并使用 ag-Grid Vue: ```vue <template> <ag-grid-vue :columnDefs="columnDefs" :rowData="rowData" class="ag-theme-alpine" ></ag-grid-vue> </template> <script> import { AgGridVue } from 'ag-grid-vue'; export default { components: { AgGridVue, }, data() { return { columnDefs: [...], // 列定义 rowData: [...], // 行数据 }; }, }; </script> <style> @import '~ag-grid-community/dist/styles/ag-grid.css'; @import '~ag-grid-community/dist/styles/ag-theme-alpine.css'; </style> ``` 在上面的示例中,您可以通过传递列定义(columnDefs)和行数据(rowData)来配置 ag-Grid Vue 组件。您还需要为 ag-Grid 使用的主题样式添加对应的 CSS。 只是一个简单的示例,您可以根据您的需求和数据结构进行更多的配置和自定义。您可以参考 ag-Grid Vue 的官方文档以获取更多详细信息和示例代码。希望这可以帮助您开始使用 ag-Grid Vue!如果有任何其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值