Lookup Tables?


#1

Hey All -

I'm new to RadZen - and I was wondering if it's possible to get a column in a DataGrid to lookup labels based on values in the data? For example, I have numbers in columns for "Month", I would like RadZen to use a lookup table to substitute the words "January", "February", etc for each number. I am doing the same for day of the week, etc.

Is this possible using RadZen? This is what we were doing using ScripCase, and we're hoping to switch over to RadZen.

Thanks is advance.


#2

Hi,

Yes, Radzen supports lookup tables. If there is a foreign key constraint between the tables Radzen will create a data grid column which will map the foreign key to the first table column which is text. This is demonstrated in our live demo: https://demos.radzen.com/products. The Products table has a foreign key to Categories and Suppliers. Radzen has inferred that and displayed the CategoryName during database scaffolding.

If you don't have a dedicated table for the months you can still create a lookup by using the Template of the column. You can create a page property with all month names e.g. ['January', 'February'] and set the Template property of the Month column to ${months[data.Month]}.

Hope this helps!


#3

Thank you for your fast reply. I will try this.

I appreciate that you have made some documentation, and some videos to show examples, but I wish there was some more in depth information about adding these sorts of things - what the syntax should be, where to enter what, etc. I don't even know what language RadZen is using, is it Angular, TypScript, etc.?

A little deeper documentation would be appreciated. The videos are nice, but there is no voiceover, and they go through things very fast.


#4

You can find more info about what languages Radzen uses in the Architecture help topic. Then you can check the fundamentals which explain what properties and expressions are.


#5

Thanks very much!

That worked like a charm - I appreciate your fast response.

This is exactly what I have been looking for. Thanks again.


#6

Next question...

How would I do the same thing for a Chart - since the Chart doesn't have a "Template" property? I have a Bar Chart that I am feeding the same data to - so I will need to get the "months" to be displayed in the legend, as well as the labels to be the month names.


#7

Indeed the open source chart component that we use doesn't support templates. You would have to transform the data to contain the month name. This can be done using the JavaScript Array.map method. When you do a Set property action to initialize the page property which contains your data you can "map" over the data source method result and transform it appropriately:

result.value.map(item => { 
  return {
     ...item, 
     Month: this.months[item.Month] 
  };
})

Then you can use the Month property in the Chart - it will be the month name instead of the index.