Grid enable/disable Column

Dear Support

JMix 2.3.3

I have a Grid in which I want to enable / disable some Columns by the controller based on some database entries. The enabling/disabling happens in onInit().

I only see the ability to set the width to 0. But as there are 97 columns in the grid, it might lead to a loading issue if there are only 20 columns to display.

What is the suggestion ?

Best regards

Felix

Hi!

It’s not entirely clear what problem you’re having. You can control the visibility of the column using the io.jmix.flowui.component.grid.DataGridColumn#setVisible method.

Regards,
Dmitriy

Hi Dmitry

Thank you for your fast reply.

Indeed, I can use setVisible(false), thank you.

My question is: I have 97 columns defined. But for some users I need only 20 columns. Does it make sense to load 97 columns and make 77 columns notVisible ?

Or should I define in the descriptor a grid and add the columns programmatically ?

Regards
Felix

If you define 97 columns and hide most of them, it will be:

  1. A lot of code.
  2. All 97 columns will be created using loaders from XML → processor time will be wasted.
  3. All these objects will be stored in the heap and will not be used → memory will be wasted.

It seems to me that it would be more optimal to define an empty dataGrid and programmatically add columns to it. This way unnecessary columns will not be calculated and created, thus saving time and memory.

Regards,
Dmitriy

Hi Dmitriy

Great, so we see it the same.

Do you have a sample how to add a column to the grid ? I am stuck with the renderer …


Grid.Column<TObject> col1 = new Grid.Column<TObject>(tObjectsDataGrid, "objCommonName", renderer);
tObjectsDataGrid.add( col1 );

Thank you !

Columns must be added using the metaPropertyPath: io.jmix.flowui.component.grid.DataGrid#addColumn(java.lang.String, io.jmix.core.metamodel.model.MetaPropertyPath).

An example of creation of a columns programmatically can be viewed in our online demo application: UI Samples :: DataGrid var columns

Hi Dmitriy

Finally I had time to try to add the columns to the grid. Attached you find the Sample.zip (115.9 KB).

Based on the table TSysFieldList it is possible to select fields to add to the grid with a sorting order which is working.

There are 2 problems

  • the data are not populated
  • i cannot edit any field anymore

Which little point did I miss ( I think the added span() might be the problem ).

Thank you for your help !