I need to manipulate a column before it is displayed in a datagrid. The column is numeric and I need to convert it to text and pad the beginning with spaces or an underscore to simulate an indentation scheme. I was able to create custom code that worked fairly well for the indentation but need to apply it to a column in the datagrid and cannot figure out how to do that.
Here is my custom code:
public IActionResult FormatNum(double x)
{
string inString = x.ToString();
int len = inString.Length;
string formattedNum = inString.PadLeft(len*2,'_');
return Json(new { formattedNum });
}
This may not be exactly what I am looking for but something close to this anyway. I tried to access the custom code from the column's template but it does not seem like that is possible. Is there any way to accomplish this?
Thanks for the reply. I did manage to get something working but for some reason the datagrid column automatically removes leading spaces. If I pad the beginning with "_", I can see that my logic is working but spaces seem to be getting trimmed automatically. Is there a way to prevent this?