This is a migrated thread and some comments may be shown as answers.
Conditional column show/hide
2 Answers 148 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stéphan Parrot
Top achievements
Rank 1
Stéphan Parrot asked on 05 May 2010, 03:15 PM
Hi, I'm trying to achieve something like this:

Show a grid with dynamic columns based on the values of objects displayed in the grid.
For instance, my object has 4 properties: Prop1 to Prop 4.
I have a textbox to search into my objects for specific types of objects. Let's say I have 3 types of objects which will have some of  the "PropX" properties set to NULL as follow:

Type 1 object

Prop1 has values
Prop2 has values
Prop3 Is always null
Prop4 Is always null

Type 2 object
Prop1 Is always null
Prop2 Is always null
Prop3 has values
Prop4 has values

Type 3 object
Prop1 Is always null
Prop2  has values
Prop3 has values
Prop4 Is always null

What I want to achieve is when I output my grid, only the columns bound on properties that has values will be visible.
Is it possible?

Thanks!

2 Answers, 1 is accepted

Sort by
0
Stéphan Parrot
Top achievements
Rank 1
answered on 05 May 2010, 03:27 PM
Again, nevermind...
I answered my own question just by re-reading my post...
If the collection of object that is returned is always of the same type, which is the case, I can simply select the first object in the collection and check if there's a value  and if so, bind it as follow:

.Columns(columns =>  
{  
            if (Model!= null && Model.Any() && Model.First().Prop1 != null)  
                columns.Bound(o => o.Prop1 ;  
}) 

Maybe it'll help some other people out there! :)

Later!
0
Vaishali
Top achievements
Rank 1
answered on 26 Jul 2012, 06:11 PM
thanks!
Tags
Grid
Asked by
Stéphan Parrot
Top achievements
Rank 1
Answers by
Stéphan Parrot
Top achievements
Rank 1
Vaishali
Top achievements
Rank 1
Share this question
or