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

column visible=false works, true does not?

1 Answer 891 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 05 Apr 2018, 05:38 PM

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?

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 10 Apr 2018, 12:04 PM
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.
Tags
Grid
Asked by
Christian
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or