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

[Solved] capture column hide/show server side

3 Answers 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Shuchi
Top achievements
Rank 1
Shuchi asked on 04 Jun 2012, 05:30 PM
Hi

I am using the ColumnContextMenu() feature to hide/show columns client side.

Is there a client side event when a use hides/shows a column? I would like to handle this event to save the column display settings in database for each user.

For example, I handle the column reorder/resize events as follows:
 
@(Html.Telerik().Grid<LitCollectionDB.Domain.Queries.RequestListDto>().
Name(Model.GridID).
        .ClientEvents(e =>
            e.OnColumnResize("onColumnResize").OnColumnReorder("onColumnReorder")        
    )

 <script type="text/>
        function onColumnResize(e) {
            $.ajax({
               ....
            });
        }

        function onColumnReorder(e) {
            $.ajax({...
            });
        }
</script>

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 07 Jun 2012, 10:39 AM
Hello Shuchi,

There isn't a supported event that is triggered when a column is shown or hidden but you can use custom code to bind to the header contextmenu event and the Grid context menu checkboxes change events to achieve this. The Grid's OnLoad client-side event in the snippet below can be used for that purpose:
function onLoad(e) {
    var grid = $(this).data("tGrid");
    //bind to the context menu of the Grid's header
    $(this).find(".t-grid-header").bind('contextmenu', function (e) {
        //wait for the menu to be generated
        setTimeout(function () {
            // bind to the checkboxes change event. The context menu has ID in the format "GridName" + "_contextmenu"
            $('#Grid_contextMenu :checkbox').change(function () {
                var $checkbox = $(this);
                // the checked state will determine if the column has been shown or hidden
                var checked = $(this).is(":checked");
                // get the index and the corresponding column from the Grid's column collection
                var columnIndex = $(this).data("field");
                var column = grid.columns[columnIndex];
                var member = column.member;
            });
        });
    });
}


Kind regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Shuchi
Top achievements
Rank 1
answered on 07 Jun 2012, 10:11 PM
Thanks Daniel, the custom handling worked. 

When a user hides a column, I set the visibility of the column to false. After this when the user displays the context menu again, the hidden columns do not show up in the list. Is it possible to list the hidden columns, with their checkboxes unchecked?

0
Daniel
Telerik team
answered on 11 Jun 2012, 07:17 AM
Hello again Shuchi,

I am not exactly sure if I understand correctly the question. If you want to hide the column on the server, you should use the Hidden configuration method. When using the Visible method, the column won't be rendered at all so it cannot be shown or hidden through the context menu.

All the best,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Grid
Asked by
Shuchi
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Shuchi
Top achievements
Rank 1
Share this question
or