I want a table to be searchable by an ID, which is not the primary ID. However my database returns this ID column as a JSON object which looks like this:
{ "$ref": "chats/QVxMsOh3Qz1vied7IXyl" }
I have set the search term for the table as:
{{ textInput2.value }}
When I search for the ID (QVxMsOh3Qz1vied7IXyl in this case), the table doesn't show the relevant entry, but instead shows empty. The same happens when I convert the JSON to a string (via table editor -> column -> format) and then search for the exact string. Maybe the {} are messing up the search query?
How can I get this to be searchable? How can I just show the ID part that's inside the JSON object as a string in the table?
I'm new to retool, so I'm sure there's a good way to do this that I'm missing. Thank you for your help!
Hi there @nicedev,
If indeed your column data is returned as a JSON object (you can double check that by right-clicking on your table > "View state" and expand the Data object to see how your data is being read by your table) then you can use the "Mapped value" option within your column settings.
- Keep format as String
- Add the following to Mapped value: {{ item.$ref.split('/').pop() }} (the split and pop will remove the "chats/" part of your id to leave only the id.
- Once you're done that you should have only the id which is then used in the search term.
If this doesn't work, would you mind sending a couple of screenshots of your Table's state with a view of how your data is being formatted? It could be that is being treated as a string as well...
1 Like
Thank you very much, that works!
1 Like