column visible=false works, true does not?

2 posts, 0 answers
  1. Christian
    Christian avatar
    69 posts
    Member since:
    Apr 2008

    Posted 05 Apr 2018 Link to this post

    I have a combobox with checkboxes to choose what columns in a grid to have visible and not, the grid and combobox is ajaxified.

    on the combobox itemChecked event i find the appropiate column and set its visibility value based on the checkbox, all very simple enough,

    protected void cmbGridColumnChooser_ItemChecked(object sender, RadComboBoxItemEventArgs e)
        {
            grCases.Columns.FindByUniqueName(e.Item.Value).Visible = e.Item.Checked;
            var test = grCases.Columns.FindByUniqueName(e.Item.Value).Visible;
        }

     

    However, setting the column to visible=false works great But when setting the column visible to visible=true again does not, even though the checkbox state shows true, and after checking the columns visible state straight afterwords (its true) the column still wont appear.

     

    Any ideas anyone?

  2. Attila Antal
    Admin
    Attila Antal avatar
    496 posts

    Posted 10 Apr 2018 Link to this post

    HI Christian,

    The problem is that the Property is being set a late stage, when RadGrid has already prepared the table. In that case, rebinding the grid will solve this problem.
    protected void RadComboBox1_ItemChecked(object sender, RadComboBoxItemEventArgs e)
    {
        RadGrid1.Columns.FindByUniqueName(e.Item.Value).Visible = e.Item.Checked;
        RadGrid1.Rebind();
    }

    I would, however, advise using the Display property instead. This does not require rebinding the grid.
    protected void RadComboBox1_ItemChecked(object sender, RadComboBoxItemEventArgs e)
    {
        RadGrid1.Columns.FindByUniqueName(e.Item.Value).Display = e.Item.Checked;
    }

    Or in case, you wish, you could use the client-side methods to show or hide columns, thus you can eliminate additional postbacks.


    Attached I am sending you two samples, one of which demonstrates show/hide columns using server-side, while the other is on client. Please try them out and see if they are suitable for your project.

    Kind regards,
    Attila Antal
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top