Questions about Cinder

This is a really cool library and I've toyed around with it a little bit, but I do have a couple questions I was hoping someone could help out with. Are you able to do queries for the filters? For example, say we have a timestamp expired_at but we want a dropdown select the the options expired or active rather than a datetime range, is that possible? I couldn't quite figure out how to set the filter to say I want one to be the nil values and the other to be not is_nil(expired_at. And with calculations, can we have them as one of the columns? Say we have a full_name calculation that combines first_name and last_name. Can we just do user.full_name or would we need to explicitly load it to get it to work? Finally, would we be able to build selectors for the rows themselves that would allow us to check individual rows (or even all visible rows if the checkbox is the one in the header) to do bulk actions on things in the table? I know it's not one of the features, but wondering if we could tap into it relatively easy to make it work that way or if it'd be more trouble than its worth.
3 Replies
sevenseacat
sevenseacat4mo ago
re: calculations - you can do sorting/filtering on them without explicitly loading them. however, if you want to render the full name in a table cell for example, you'll need to explicitly load the calculation as part of the query_opts. for filtering, you may want to look at suppliyng a custom filter_fn that does custom filtering based on a value. eg.
<:col field="expired" filter={:boolean} filter_fn={&is_expired?/2}>...</:col>

defp is_expired?(query, value) do
if value do
Ash.Query.filter(not is_nil(expired_at))
else
Ash.Query.filter(is_nil(expired_at))
end
end
<:col field="expired" filter={:boolean} filter_fn={&is_expired?/2}>...</:col>

defp is_expired?(query, value) do
if value do
Ash.Query.filter(not is_nil(expired_at))
else
Ash.Query.filter(is_nil(expired_at))
end
end
filter_fn appears to be missing from the docs 😦
Steve
SteveOP4mo ago
Yeah, I was looking through the docs to see if there was a way before asking about it haha. I'll give that a shot, thanks! 🙏 Do you think I'd be able to tie into this table to do the select box thing? I'll give it a shot later tonight, just wondering if you might have some insight
sevenseacat
sevenseacat4mo ago
its not built in, but it seems like a reasonable feature. I think it could be manually implemented currently - add a column without a field, that has a checkbox and calls an event to record the ID of the item that was checked. then you can add your buttons that do things with the list of checked items

Did you find this page helpful?