Primefaces static and dynamic columns in datatable

后端 未结 2 1973
礼貌的吻别
礼貌的吻别 2020-11-27 07:43

I am using Primefaces 5.0 to create a dynamic datatable.

My DataObject has some required fields and a List of optional \"tupel\" (key-value pair). The optional list

2条回答
  •  北海茫月
    2020-11-27 08:17

    It isn't possible to define columns based on row data. Imagine that row 1 has 2 columns, row 2 has 6 columns, row 3 has 1 column, etc how would you ever produce a technically valid table in HTML? Each row must have the same amount of columns.

    You've 2 options, depending on whether can change the model or not:

    1. If you can't change the model, then you need to replace that by a single and loop over the #{data.optionalValues} using a nested loop with e.g. or perhaps even another :

      
          
              
                  #{opt.value}
              
          
      
      
    2. If you can change the model, then you need to let point to a bean property instead of to a row property, so that it's exactly the same for every row. This works if you replace List optionalValues by Map optionalValues where the key is Tupel#id and add a List property to the bean containing all available Tupel#id values.

      
          #{data.optionalValues[id].value}
      
      

提交回复
热议问题