简体   繁体   English

在 FramerX 中设置 AG-Grid 组件

[英]Setting Up an AG-Grid Component in FramerX

I'm working on a prototype in FramerX, and our production software uses Ag-Grid for a large number of components.我正在使用 FramerX 制作原型,我们的生产软件使用 Ag-Grid 来制作大量组件。 I need to be able to incorporate Ag-Grid in my latest prototype.我需要能够在我最新的原型中加入 Ag-Grid。

Does anyone know how I can go about setting this up at the most basic level?有谁知道我如何在最基本的层面上进行设置?

I was able to figure out how to make the simple ag-grid table provided in the AG-Grid starter tutorial: https://stackblitz.com/edit/ag-grid-react-hello-world我能够弄清楚如何制作 AG-Grid 入门教程中提供的简单 ag-grid 表: https://stackblitz.com/edit/ag-grid-react-hello-world

The trick was that I forgot that FramerX uses TypeScript syntax so there were a few things that need to be modified about the example.诀窍是我忘记了 FramerX 使用 TypeScript 语法,所以对于这个例子有一些需要修改的地方。 Below is the code I ultimately ended up using.下面是我最终使用的代码。 I'll go through the edits that I had to make.我将通过我必须进行的编辑 go。

import * as React from "react"
import { Frame, addPropertyControls, ControlType } from "framer"
import { AgGridReact } from "@ag-grid-community/react"
import { AllCommunityModules } from "@ag-grid-community/all-modules"

import "@ag-grid-enterprise/all-modules/dist/styles/ag-grid.css"
import "@ag-grid-enterprise/all-modules/dist/styles/ag-theme-material.css"

interface MyProps {}

interface MyState {
    columnDefs: object
    rowData: object
}

export class Simple_Table extends React.Component<MyProps, MyState> {
    //Set the data for the Table
    constructor(props) {
        super(props)
        this.state = {
            //Set the Columns
            columnDefs: [
                {
                headerName: "Make", field: "make"
                }, {
                headerName: "Model", field: "model"
                }, {
                headerName: "Price", field: "price"
                }
            ],
            //Set the actual data
            rowData: [
                {
                make: "Toyota", model: "Celica", price: 35000
                }, {
                make: "Ford", model: "Mondeo", price: 32000
                }, {
                make: "Porsche", model: "Boxter", price: 72000
                }
            ],
        }
    }

    render() {
        return (
            <Frame
                style={{ height: "368px", width: "784px", background: "#FAFAFA" }}
                className="ag-theme-material"
            >
                <AgGridReact
                    columnDefs={this.state.columnDefs}
                    rowData={this.state.rowData}
                    modules={AllCommunityModules}
                ></AgGridReact>
            </Frame>
        )
    }
}

First instead of calling out React and Component separately in the import like this:首先,不要像这样在导入中分别调用 React 和 Component:

import React, { Component } from 'react';

I imported React with the wildcard like show Framer typically does it:我使用通配符导入 React,例如 show Framer 通常会这样做:

import * as React from "react"

Then since this is TypeScript with React, you need to define the props and states in the interface before the component.那么既然这是 TypeScript 和 React,你需要在组件之前定义接口中的 props 和 states。 Make sure that the states are set as objects because they will be arrays.确保将状态设置为对象,因为它们将是 arrays。

interface MyProps {}

interface MyState {
    columnDefs: object
    rowData: object
}

Then I rewrote the component function to have the export at the beginning, and called "MyProps" and "MyState" interfaces in the function, again since this is TypeScript.然后我重写了组件 function 以在开头有导出,并在 function 中调用“MyProps”和“MyState”接口,再次因为这是 Z558B544CF685F39D34E4903E

export class Simple_Table extends React.Component<MyProps, MyState> {...}

Last but not least, I changed the <div>...</div> to a <Frame>...</Frame> by including Framer's module:最后但同样重要的是,我通过包含 Framer 的模块将<div>...</div>更改为<Frame>...</Frame>

import { Frame, addPropertyControls, ControlType } from "framer"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM