Adding custom columns to filter or custom search query for a mongodb

Hi I’ve created a few custom columns, but these don’t seem to show up in the built in filters, and since these are custom columns not in the mongodb I assume I can’t query them to work in my created search box. How can I add these columns in the filter options?

Hey @Patsy_Count! This is currently being worked on, but in the meantime, would this workaround be helpful?

http://community.retool.com/t/table-filter-by-a-custom-column/9230

Let me know if you have any questions at all! :slight_smile:

Hi is there a similar solution from monogeneans since that solution is for sql databases, also where can I find the column mapper option.

Hey Patsy! The solution in that thread should work for any data sources—the only caveat being the very first line of the code. If your data is already an array of objects (which MongoDB data does get returned as), then you don't need to convert it into one.

You'll need to create a JS transformer and run this code

const data = {{ yourMongoQuery.data }} 
data.forEach(row => { row.new_row = row.rating * 100 return row; }) 
return data;

Then in your table, you'll just use the JS transformer.value as the data source instead of your original Mongo query!

To answer your second question, the table.columnMappers property gets populated by Custom Column data so it can be helpful if you need to access your Custom Column data; otherwise, Custom Columns are just for display only and can't really be accessed anywhere else.

Let me know if you have any other questions!

Is it possible to specify column order? What if I wanted to insert new_row after my id column?

Great question. Since we’re creating new columns by adding a new key value pair to each row object in our data array and objects are by definition unordered in JS, the only way to guarantee order is to rearrange your table columns in your table settings on the right hand panel!