56
Views
6
Comments
Solved
DataGrid - autogenerate columns with configuration file
Question

Good afternoon,

I'm having a problem using the DataGrid with the AutoGenerateColumns as True, and I want to use the Configuration file to save the applied filter to the column.

As far as I read there is some incompatibility with using the AutoGenerateColumns as True and using the json file that is generated for the configs.

I've tried saving the configs in multiple ways:

1- I tried removing the layout from the json, that results in a javascript error.

2-I tried leaving the layout as "layout":"{}"

3-I tried "layout":"{\"columns\":[{}]" gives me

Json file:

{

   "extra":{ },

   "frozenColumns":0,

   "groups":{   },

   "rendered":{   },

   "selection":{   },

   "layout":"{\"columns\":[{\"name\":\"Contract type\",\"header\":\"Contract type\",\"binding\":\"Contract type\",\"dataType\":1},{\"name\":\"Col2\",\"header\":\"Col2\",\"binding\":\"Col2\",\"dataType\":1}]}",

   "groupsCollapsable":0,

   "filterDefinition":"{\"defaultFilterType\":3,\"filters\":[{\"binding\":\"Contract type\",\"type\":\"value\",\"sortValues\":true,\"maxValues\":250,\"exclusiveValueSearch\":true,\"showValues\":{\"Maintenance\":true,\"Operational lease\":true,\"Own resources\":true}}]}"

}

https://learn.microsoft.com/en-us/windows/communitytoolkit/controls/datagrid_guidance/customize_autogenerated_columns

2023-04-05 12-00-44
Marco Damião
Solution

After some investigation I found a workaround for this issue:

To be able to use the AutoGenerateColumns with a filter configuration I needed to add a fixed column that exists so that we can use the configuration + a fixed column.

This seems to fix the problem. 

Oml is in attachment.

1- Set AutoGenerateColumns dynamicly with a variable that will determine if we have any configuration saved for this table or not.

2- We should have a if condition with the HasFilters flag, if we have a filter applied we want to use and GridColumnAdvanced component with the JSONField set to a column that exists. 

3- the Set to no filter was just to test, for a real situation you should check if the GridConfigurations has any configuration for this dataGrid.

DatagridTest_solution.oml
2023-04-05 12-00-44
Marco Damião

EDIT:

I'm having a problem using the DataGrid with the AutoGenerateColumns as True, and I want to use the Configuration file to save the applied filter to the columns.

As far as I read there is some incompatibility with using the AutoGenerateColumns as True and using the json file that is generated for the configs.

I've tried editing the configs in multiple ways without sucess:

1- I tried removing the layout from the json, that results in a javascript error.

2-I tried leaving the layout as "layout":"{}"

3-I tried "layout":"{\"columns\":[{}]" 

The Json file created by the configuration is the following.

Json file:

{

   "extra":{ },

   "frozenColumns":0,

   "groups":{   },

   "rendered":{   },

   "selection":{   },

   "layout":"{\"columns\":[{\"name\":\"Contract type\",\"header\":\"Contract type\",\"binding\":\"Contract type\",\"dataType\":1},{\"name\":\"Col2\",\"header\":\"Col2\",\"binding\":\"Col2\",\"dataType\":1}]}",

   "groupsCollapsable":0,

   "filterDefinition":"{\"defaultFilterType\":3,\"filters\":[{\"binding\":\"Contract type\",\"type\":\"value\",\"sortValues\":true,\"maxValues\":250,\"exclusiveValueSearch\":true,\"showValues\":{\"Maintenance\":true,\"Operational lease\":true,\"Own resources\":true}}]}"

}

Not sure if it's related but I found this url with some explanation of why it's incompatible.

https://learn.microsoft.com/en-us/windows/communitytoolkit/controls/datagrid_guidance/customize_autogenerated_columns

2021-09-06 15-09-53
Dorine Boudry
 
MVP

I'm not sure but I don't think that Microsoft page is about the wijmo datagrid that Outsystems component is using.

Please share an oml demostrating what you are doing and where it goes wrong.  Some things that come to mind : are you using the correct client actions to get and set filter options, and are you doing it at an appropriate time (i.e. after retrieving data)

2023-04-05 12-00-44
Marco Damião

Hey Dorine,

So I'm using the ConfigurationSaveButton and the ConfigurationResetButton to save or reset the filter configs of the table.

I posted the oml in attachment with this test.

The situation that's happening is the following:

1- The data loads correctly in the example

2-I apply a filter and hit the save configuration button (the action I'm using is the ConfigurationSaveButton from the DataGridWeb from the forge)

3- when I reload the page I get the columns duplicated.

DatagridTest.oml
2021-09-06 15-09-53
Dorine Boudry
 
MVP

aah,

you are talking about DataGridWeb, not DataGrid (which is a reactive component)  Unfortunately, I know almost nothing about the traditional web version, so other than confirming your story, I don't have ideas about how to deal with this.

Dorine

2023-04-05 12-00-44
Marco Damião

Thank you anyway Dorine.

I'm currently working on a work around. If successful I'll leave my solution here.

2023-04-05 12-00-44
Marco Damião
Solution

After some investigation I found a workaround for this issue:

To be able to use the AutoGenerateColumns with a filter configuration I needed to add a fixed column that exists so that we can use the configuration + a fixed column.

This seems to fix the problem. 

Oml is in attachment.

1- Set AutoGenerateColumns dynamicly with a variable that will determine if we have any configuration saved for this table or not.

2- We should have a if condition with the HasFilters flag, if we have a filter applied we want to use and GridColumnAdvanced component with the JSONField set to a column that exists. 

3- the Set to no filter was just to test, for a real situation you should check if the GridConfigurations has any configuration for this dataGrid.

DatagridTest_solution.oml
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.