String Format

Hello,

In a datagrid, I have the following structure of string data in a column:

  • word_number_unnecessary
  • another_one_unncessary
  • next_unnecessary
    ...

Here, I need to strip the "_unnecessary" part of each row of this column. Can you please give me a clue how to do this? I checked the column's Format and FormatString properties but could not understand how can I use it?

Thanks,

Hi @ozgur_agi,

Is the "unnecessary" part of the column data? Can you paste here how the actual data looks in JSON format? Or a screenshot of it?

Hello,
Thank you for your quick reply.
I cannot show the actual data but a visualization is in the picture.

So, basically I need to strip out the part after the last underscore.

In that case you can use the replace method of the string to remove it. Try setting the Template property of the DataGrid column to something like ${data.column2.replace("_unnecessary", "")}

Thank you for this reply, it is actually working.

When I need regular expressions, how can I do that?

I tried:

  • ${data.column2.replace(/^(.*)_([A-Z]+)$/g,"\$1")}
  • ${data.column2.replace(/^(.*)_([A-Z]+)$/g,"$1")}

I actually need this since in other datagrids, I will have non constant string "_unnecessary" at the end of the data, like "_STRING", "_INT".

Best,

Hello,

can you please help with this regular expression question?

Thanks :slight_smile:

As far as I know Angular doesn't support regular expression literals in its Templates. You will need to add a method to your page.component.ts file which does the replace.

class YourPageComponent extends YourPageComponentGenerated {
     replace(value) {
        return value.replace(/^(.*)_([A-Z]+)$/g,"\$1");
     }
}

Then set the template like this:

${replace(data.column2)}

1 Like

Solved the issue.

Thank you @korchev :slight_smile: