simov / express-admin

MySQL, MariaDB, PostgreSQL, SQLite admin for Node.js
MIT License
1.18k stars 223 forks source link

Support for postgres data type json? #147

Open MaVoit opened 5 years ago

MaVoit commented 5 years ago

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
                }
            }
yusufyildirim commented 5 years ago

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.

MaVoit commented 5 years ago

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 notifications@github.com 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.

yusufyildirim commented 5 years ago

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

MaVoit commented 5 years ago

👍🏻

On 20 Oct 2018, at 21.46, Yusuf YILDIRIM notifications@github.com 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.