express-admin icon indicating copy to clipboard operation
express-admin copied to clipboard

Support for postgres data type json?

Open MaVoit opened this issue 6 years ago • 4 comments

Is there any way I can display the value of a column with datatype json in the edit view? Currently I am just getting the string representation of the object, which is [object Object].

settings.json:

            {
                "name": "custom_data",
                "verbose": "Data",
                "control": {
                    "text": true
                },
                "type": "json",
                "allowNull": true,
                "defaultValue": null,
                "listview": {
                    "show": true
                },
                "editview": {
                    "show": true
                }
            }

MaVoit avatar Oct 17 '18 18:10 MaVoit

Hey, I was facing with the same issue and I tweaked the library a bit :D In the end, I did this: https://github.com/yusufyildirim/express-admin/commit/daf359f09bc2cd7dcc5e06bac8ec70c59271f29b

This allows you to use "text" control but converts JSON objects to the string so you can see it in edit view. Propably, we need to add extra json viewer or something like that to edit our json easily but in my case, I don't need it for now because my json datas are simple arrays.

If you want help, please comment so maybe I can help you to improve this.

yusufyildirim avatar Oct 19 '18 16:10 yusufyildirim

Yes, excellent tip. I was thinking of doing exactly the same, but was hoping that I wouldn’t have to fork the repo and that I was just missing something :)

On 19 Oct 2018, at 19.09, Yusuf YILDIRIM [email protected] wrote:

Hey, I was facing with the same issue and I tweaked the library a bit :D In the end, I did this: yusufyildirim@daf359f

This allows you to use "text" control but converts JSON objects to the string so you can see it in edit view. Propably, we need to add extra json view or something like that to edit our json easily but in my case, I don't need it for know because my json datas are simple arrays.

If you want help, please comment so maybe I can help you to improve this.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

MaVoit avatar Oct 20 '18 17:10 MaVoit

I found a bug today. Sometimes, this function triggers for the same data and this behavior causes a problem. Assume you have a json array like ["A", "B", "C"], if you convert it to string with JSON.stringfy method, everything is allright but if you do the same thing again to that string, you found yourself with a data like "[\"A\", \"B\", \"C\"]". To prevent this, I changed my code a bit. Here is my new approach: https://github.com/yusufyildirim/express-admin/commit/b6980f4f5ec0fe4810bc812d6736d31bea518427

yusufyildirim avatar Oct 20 '18 18:10 yusufyildirim

👍🏻

On 20 Oct 2018, at 21.46, Yusuf YILDIRIM [email protected] wrote:

I found a bug today. Sometimes, this function triggers for the same data and this behavior causes a problem. Assume you have a json array like ["A", "B", "C"], if you convert it to string with JSON.stringfy method, everything is allright but if you do the same thing again to that string, you found yourself with a data like "["A", "B", "C"]". To prevent this, I changed my code a bit. Here is my new approach: yusufyildirim@b6980f4

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

MaVoit avatar Oct 20 '18 20:10 MaVoit