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

Hide Columns (Client)

3 Answers 14 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Developer
Top achievements
Rank 1
Developer asked on 18 Sep 2014, 07:38 AM
Hi,

I need to be able to show / hide (toggle) all columns in a grid view where the columns name begins with (A).  I've search and found this script:

function HideColumn(index)
           {
               var columnCount = RadGrid1.get_masterTableView().get_columns().length - 1;
               if (index < 0 || index > columnCount)
               {
                   alert("Invalid index! The valid range is: " + 0 + "-" + columnCount);
               }
               else
               {
                   RadGrid1.get_masterTableView().hideColumn(index);
               }
           }


Does anybody have any suggestions how it could be tailored to accomplish my goals?

3 Answers, 1 is accepted

Sort by
0
Developer
Top achievements
Rank 1
answered on 18 Sep 2014, 08:32 AM
I've made some progress with this, the bit I'm now stuck on is how to create the toggle functionlaity, i.e. how cna clicking the button again turn back on the hidden columns, is there is a unhide all function?

function HideColumn() {
    var masterTableView = RadGrid1.get_masterTableView();
    var columns = masterTableView.get_columns();
 
    for (var i = 0; i < columns.length; i++) {
        var hasPrefix = columns[i].get_element().innerHTML.startsWith("(A)");
        if (hasPrefix === true) {
            RadGrid1.get_masterTableView().hideColumn(i);
        }
    }
}
0
Developer
Top achievements
Rank 1
answered on 18 Sep 2014, 09:26 AM
Third update, I now have button within the CommandItemTemplate, when this is clicked it runs some js and hide the columns.  The problem is although code has a line to disable the button, when it runs it quickly disables it and the automatically re-enables it - any ideas what might be causing this?

Here is the code:

function HideColumn() {
    var masterTableView = RadGrid1.get_masterTableView();
    var columns = masterTableView.get_columns();
    for (var i = 0; i < columns.length; i++) {
        var hasPrefix = columns[i].get_element().innerHTML.startsWith("(A)");
        if (hasPrefix === true) {
            RadGrid1.get_masterTableView().hideColumn(i);
        }
    }
    var testButton = $telerik.findControl(RadGrid1.get_element(), "TestButton");
    testButton.set_enabled(false);
}
0
Angel Petrov
Telerik team
answered on 23 Sep 2014, 06:04 AM
Hi,

Could you please ensure that a postback does not occur after the button is disabled?

In order for us to further investigate the matter I would like to ask you to share with us the markup and code-behind of the page so we could examine the exact implementation.

Regards,
Angel Petrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Developer
Top achievements
Rank 1
Answers by
Developer
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or