The Retool table has the option to use 'Search term' using the value of a text input. I would like to access the same search algorithm, in my own transformer.
Hey @ali-sajjad-rizavi,
You could use something like the one shown here.
It's quite simple and it may need adapting to your specific data set.
1 Like
You can also use this function that searches the term across all columns (of type string, not arrays):
const Rows = {{ Table.data }};
const str = {{SearchTerm.value.toLowerCase() }};
const result = Rows.filter((Row) => {
Object.entries(Row).filter((Column) => {
if (typeof Column[1] == String)
return Column[1].toLowerCase().includes(str);
else return false;
}).length > 0;
});
return formatDataAsObject(result);
And this function use the JSON.stringfy() to turn the whole row into a string and then search it:
const Rows = {{ Table.data }};
const str = {{SearchTerm.value.toLowerCase() }};
const result = Rows.filter((Row) =>
JSON.stringify(Row).toLowerCase().includes(str)
);
return formatDataAsObject(result);
You can also make this a global function with parameters so that you can use it for app your apps.
Hope this helps!