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

hide/show column client-side by uniquename or datafield

2 Answers 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Albert Shenker
Top achievements
Rank 1
Veteran
Albert Shenker asked on 03 Jan 2017, 04:27 PM
I know you can hide columns client-side using masterTableView.hideColumn(columnIndex). However, this leads to very difficult to maintain code since column ordinals can change frequently. Is there a way to find a column by UniqueName or DataField client side and then call .hide() or show() functions, or set_visible() , or something to that effect?

2 Answers, 1 is accepted

Sort by
0
Ben
Top achievements
Rank 1
answered on 03 Jan 2017, 07:35 PM

You should be able to use the method described in the following post to get the column's index by unique name, then call the hideColumn() method using the found index.

Source: http://www.telerik.com/forums/how-to-get-column-index-from-column-name-at-client-side

 

Modified function:

function hideColumnByUniqueName(columnName) {
    var masterTableView = $find('<%= RadGrid1.ClientID %>').get_masterTableView();
    var column = masterTableView.getColumnByUniqueName(columnName);
    var element = column.get_element();
    masterTableView.hideColumn(element.cellIndex);
}

 

Hope this helps

0
Albert Shenker
Top achievements
Rank 1
Veteran
answered on 03 Jan 2017, 07:45 PM
Thanks. That seems to have worked. Hopefully they'll just add hide/show methods to the column object at some point in the future.
Tags
Grid
Asked by
Albert Shenker
Top achievements
Rank 1
Veteran
Answers by
Ben
Top achievements
Rank 1
Albert Shenker
Top achievements
Rank 1
Veteran
Share this question
or