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

Hide column of a details grid

1 Answer 314 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cornel
Top achievements
Rank 1
Cornel asked on 01 Dec 2017, 03:42 PM

Hi,

I have a grid with a details template. I want to hide a column in the details template based on the value of a column from the main grid. Is this possible?

Thanks,

Cornel.

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 06 Dec 2017, 09:26 AM
Hello, Cornel,

The desired result could be achieved on the dataBound event of the child Grid. It will require selecting the master row of the Parent Grid and find its dataItem. Then based on the dataItem values, the hideColumn method can be used on the child Grid to hide the desired column:

.Events(events => events.DataBound("onDataBoundChildGrid"))


function onDataBoundChildGrid(e) {
    var grid = this;
    var parentGrid = $('#grid').data('kendoGrid')
    // the master row for this detail
    var masterRow = grid.wrapper.closest("tr").prev();
   // find the dataItem
    var dataItem = parentGrid.dataItem(masterRow)
     // perform custom action
    if (dataItem.City === "Seattle") {
        grid.hideColumn(0);
    }
}

https://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-dataBound

https://docs.telerik.com/kendo-ui/api/javascript/ui/grid#methods-dataItem

https://docs.telerik.com/kendo-ui/api/javascript/ui/grid#methods-hideColumn

I hope this is helpful.

Regards,
Stefan
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
Cornel
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or