This is a migrated thread and some comments may be shown as answers.

How to include column in grid conditionally

5 Answers 913 Views
Grid
This is a migrated thread and some comments may be shown as answers.
york
Top achievements
Rank 1
york asked on 14 Aug 2015, 10:58 PM

I have a kendo grid that I try to set different columns as follow

            .Columns(columns =>
            {
                if ((bool)ViewData["resourcePooled"])
                {
                    columns.Bound(s => s.ResourceIdAssignmentName).Width(300);
                }
                else
                {
                    columns.Bound(s => s.ResourceIdPoolName).Width(300);
                }​

But it only can set first column, i.e it works only when ViewData["resourcePooled"]=true. When ViewData["resourcePooled"]=false, it doesn't work. Note that above code works well in Telerik MVC Extension. But after in Kendo, it has above problem. I'd like to know what happen. Thanks.

 

5 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 18 Aug 2015, 07:48 AM

Hello york,

The provided sample code seems correct, so we cannot state what is the reason for the behavior on your end. Please provide small isolated runnable example (here or in a support ticket) that demonstrates the issue so we could inspect further.

Regards,
Dimiter Madjarov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
york
Top achievements
Rank 1
answered on 25 Aug 2015, 10:20 PM

Hi Dimiter,

I attach a sample to show the problem. You can run it and find out where
the problem is. Because the size limit, I remove the package in the
project. The package include, Kendo MVC (2015.1.429.440.Trial), MVC 4
and many others. The simplest way to recreate the solution is to create
new Telerik MVC project (name: MVC_Controls_Kendo) and select .Net 4 and
ASPX (not razor), and add the source files attached.

After launching the project, just click on "Display Pool Info", which will go to PoolInfo.aspx. But PoolInfo.aspx can't be displayed with error: "Specified cast is not valid".

The project has everything it is needed. If you have any question, please let me know. Thanks.

0
Accepted
Dimiter Madjarov
Telerik team
answered on 27 Aug 2015, 08:13 AM

Hello york,

We were unable to run the project on our end due to errors. Nevertheless I would suggest to try the following approach for casting the value to bool instead of the current one.
E.g.

if (Convert.ToBoolean(ViewData["resourcePooled"]))
{
   columns.Bound(p => p.ResourceIdAssignmentName).Width(300);
}

Regards,
Dimiter Madjarov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
york
Top achievements
Rank 1
answered on 27 Aug 2015, 10:53 PM

Thanks, Dimiter.

Can you take a look at another post of mine about opening a kendo window when click in kendo grid cell, http://www.telerik.com/forums/how-to-open-a-window-when-click-in-kendo-grid-cell?

0
Dimiter Madjarov
Telerik team
answered on 28 Aug 2015, 09:26 AM

Hello york,

I am glad the information was helpful. I covered the question in the other thread too.

Have a great weekend!

Regards,
Dimiter Madjarov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
york
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
york
Top achievements
Rank 1
Share this question
or