Johnny Huynh
Johnny Huynh

Reputation: 43

Auto-breakdown to separate items when copy from Excel to a Workshop filter

I am hoping to replicate the copy paste function in Contour to a Workshop application that I am building.

As you know, when you copy a list of items (e.g. from Excel) into a Contour's filter, it will automatically break them down to separate items (screenshot). I can't seem to do this in a Workshop application's filter.

enter image description here

The only way that I can think of is use a function backed text area but haven't managed to do that.

Upvotes: 0

Views: 39

Answers (1)

ZettaP
ZettaP

Reputation: 1359

Indeed, using a Function is the right move here. You will essentially parse the string and perform the operation(s) you need on it.

Example of function (untested, but should give you a high level pointer):

@Function()
function parseExcelString(excelString: string) : string[] {
  // Split the string by newlines and tabs to separate all items
  const items = excelString.trim().split(/[\n\t]/);

  return items;
}

Steps at high level:

  1. Create a code repository
  2. Select "Functions" > "Typescript"
  3. Write the above function (you will need to uncomment the import present by default)
  4. Commit (top right button) and tag (top right button)
  5. Wait for the function to be published

And in workshop:

  1. Add the text input widget
  2. Create a variable (let's call it parsed_strings_array) that is a "function execution" and that outputs a string array enter image description here
  3. Select your function published above ("parseExcelString")

You now have a variable with an array of the different values populated from what was copy-pasted by the user !

You can now use this string array variable to filter your Object set variable by selecting Filter ... On a property ... (x)

enter image description here

Upvotes: 1

Related Questions