How to include column in grid conditionally

6 posts, 1 answers
  1. york
    york avatar
    160 posts
    Member since:
    Jul 2012

    Posted 14 Aug 2015 Link to this post

    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.

     

  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2288 posts

    Posted 18 Aug 2015 Link to this post

    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
  3. york
    york avatar
    160 posts
    Member since:
    Jul 2012

    Posted 25 Aug 2015 in reply to Dimiter Madjarov Link to this post

    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.

  4. Answer
    Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2288 posts

    Posted 27 Aug 2015 Link to this post

    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
  5. york
    york avatar
    160 posts
    Member since:
    Jul 2012

    Posted 27 Aug 2015 in reply to Dimiter Madjarov Link to this post

    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?

  6. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2288 posts

    Posted 28 Aug 2015 Link to this post

    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
Back to Top