ExtJS 4:将网格转换为 JSON 以存储在数据库中或转换为 PHP 对象

发布于 2025-01-05 05:32:28 字数 167 浏览 2 评论 0原文

我想采用现有的 ExtJS 4 网格并将其转换为 JSON 对象,以便传输到我的应用程序 (PHP) 的后端。我需要做什么才能实现这一点?我是否只需要覆盖网格的 getState 方法和列对象的 getColumnState 方法?

最好的方法是什么?

I want to take an existing ExtJS 4 Grid and convert it into a JSON object for transport to the backend of my application (PHP). What do I need to do to make this happen? Do I simply need to overwrite the getState method of the grid and the getColumnState method of the column object?

What's the best approach for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最初的梦 2025-01-12 05:32:28

覆盖列的 getColumnState 是个好主意。默认情况下,它假设您将再次使用具有相同视图的数据,并且列 ID 之类的内容将是相同的。我现在有 getColumnState 返回一个可用作列配置的对象。从网格中添加您需要的任何其他内容,并在您发现有用时存储。

我发现我需要 textdataIndexhiddendraggablehideable可调整大小minWidthflex。 (有时还有宽度)。

编辑:
您想要类似的东西:

getColumnState: function () {
    return {
        text: this.text,
        ...
    };
}

如果您需要这些东西,请查看原始的 getColumnState 以了解它们对分组列和宽度与 Flex 的作用。

然后只需调用 grid.headerCt.getColumnsState() 即可

Overriding the getColumnState for the column is a good idea. By default it assumes you'll be using the data with the same view again and that things like the column ids will be the same. I now have getColumnState returning an object that can be used as a config for a column. Add on whatever else you need from the grid and store as you find it useful.

I've found I need text, dataIndex, hidden, draggable, hideable, resizable, minWidth and flex. (And sometimes width).

Edit:
You want something like:

getColumnState: function () {
    return {
        text: this.text,
        ...
    };
}

Look at the original getColumnState to see what they do about grouped columns and width vs flex if you need those things.

Then just call grid.headerCt.getColumnsState()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文