Currently in a DataGrid, if you have a column, there’s only a “key” that you can pull a value from if you are directly using the “Add Columns From Data Table” option.
What I’m proposing is changing the “key”, to “value”. So that instead of being limited to pulling a single key for a single value, you can pull multiple keys, and combine them, to a single value.
For example, if there’s a table called “people” with columns of “first_name” and “last_name”, you could put this expression into the “value” column:
first_name + last_name
To create a derived column named “Full Name”.
Or something like:
first_name + randomText()
To create a derived column called “Randomized First Name”
I think you can accomplish this with something like:
item['Full Name'] = item['first_name'] + item['last_name']
I’m struggling to describe where exactly you put this line, but I think I could show you if you want to share a clone of your use case.
1 Like
Yes, I can link an example of how I’m trying to implement:
item['Full Name'] = item['first_name'] + item['last_name']
https://anvil.works/build#clone:OQ4DIVKVRCXQYH6A=JEM37XBWO6JM6UA5R567LYUM
You’ve added the code to the data grid data key. That won’t work here.
Instead double click the row template drag a label into the column and add a databinding to the text property with the right hand side of the code you’ve written.
It’s a common pattern in the data grid tutorials, which would be worth exploring.
https://anvil.works/build#clone:CJU5IFHYQ6BB6Z5G=T7Q5MCJ2IVM5GWBW4RPHVQAU
3 Likes
@stucork, thank you for showing me that, I’ll probably use that pattern for now, but I’d still like to see something closer to just being able to enter in:
first_name + ' ' + last_name
into the columns part of the datagrid, making the column a derived field.
Currently, there’s only a “key” field, which doesn’t support what I’m talking about.
Maybe for simple derived columns, the pattern you showed me could be what happens in the background.
self.item['frist_name'] + ' ' + self.item['last_name']
types of patterns seem like it could be easily autogenerated code, along with the custom lable.
shrug