How to get attribute name of an attribute property in pluggable web widget

0
Hi everyone, I create a new pluggable web widget to simulate a data grid with multiple columns. For column definition in XML, I user attribute property. Example for attribute property for each column   <property key="field" type="attribute" dataSource="../datasource"> <caption>Field</caption> <description>...</description> <attributeTypes> <attributeType name="Integer" /> <attributeType name="Long" /> <attributeType name="String" /> </attributeTypes> </property> The problem is that I cannot get the Name (as picture above) of the attribute then using it in the Client API Mendix 10 React Client Documentation Home   Do you have any idea or document about this one?
asked
4 answers
0

Hi Quan,

 

Looking at what you pasted i think the problem might be with the datasource, i've never tried or saw it defined as you have and i'm not aware of changes like those in Mendix 10, but i think it's that. For you to have an attribute and connect it with a datasource, and i imagine this is your scenario since you want to define X columns, you need to define one with type="datasource" and then all fields you want from this datasource you put them pointing to your datasource, like this:

 

<property key="mydatasource" type="datasource">

    <caption>mydatasource</caption>

    <description>mydatasource</description>

</property>

<property key="column1" type="attribute" dataSource="mydatasource">

    <caption>Column 1</caption>

    <description>Column 1</description>

    <attributeTypes>

         <attributeType name="String"/>

     </attributeTypes>

</property>

 

You can also take a look in this documentation since it has some examples, it might help you: https://docs.mendix.com/howto/extensibility/pluggable-widgets/

 

Hope it helps, 

Rui.

answered
0

Thank Rui,

Actually, I have no problem with the data source type and the attribute type in the configuration XML file. In the widget property popup (by double click the widget in Mendix Studio Pro), I can also select a property of the data source to assign to this column too.

 

I will give a situation with the data model and your xml definition as below

image.png

<property key="mydatasource" type="datasource">
    <caption>mydatasource</caption>
    <description>mydatasource</description>
</property>
<property key="column1" type="attribute" dataSource="mydatasource">
    <caption>Column 1</caption>
    <description>Column 1</description>
    <attributeTypes>
         <attributeType name="String"/>
     </attributeTypes>
</property>

In the widget property popup, when user select the Name property for the Column 1.

How can we know which property user had selected (in this case, the Name property) in the coding?

 

I also referenced this document: List Values | Mendix Documentation, but do not have information that I need

answered
0

Hi Quan,

 

Answering to your question "How can we know which property user had selected (in this case, the Name property) in the coding?", the Name, which is the attribute that in Mendix was selected to fill the property column1, will be available for you in the structure of the widget in the attribute column1. in case that your "mydatasource" is a list, you can iterate through it and for each "mydatasourceobj", you can do column1.get(mydatasourceobj).value

 

Does this answer your question?

 

Rui.

answered
0

Hi Rui,

 

More detail in this situation to explain why I also need the property name

For example:

  • I have a grid with 3 columns named column1, column2, and column3 in the xml definition, and the developer can select any property (Name, Description, Price) of the data source for each column.
  • The end user can update the data for each column in the grid when running and save the updated data back to the database
  • Then in development, I need exactly which column go with which attribute of data source to using the set(attr, val) method of Client API and update back to the database later.

image.png

I hope it can explain it more to you.

Thank you

answered