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

Hide columns of group by condition

1 Answer 374 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Iman
Top achievements
Rank 1
Iman asked on 22 Oct 2018, 07:58 AM

Hi

I Have a grid like this :

01.@(Html.Kendo().Grid<TMain>()
02.                 .Name("gridEQ")
03.                 .Columns(c =>
04.                 {
05.                     c.Group(g =>
06.                         g.Title("History")
07.                             .Columns(i =>
08.                             {
09.                                 i.Bound(x => x.History.HairLoss).ClientTemplate("#= History.HairLoss ? 'Yes' : '' #");
10.                                 i.Bound(x => x.History.WT_Gain).ClientTemplate("#= History.WT_Gain ? 'Yes' : '' #");
11.                                 i.Bound(x => x.History.Wt_loss).ClientTemplate("#= History.Wt_loss ? 'Yes' : '' #");
12.                             })
13.                         );
14.                     c.Group(g =>
15.                         g.Title("PmhDh")
16.                             .Columns(i =>
17.                             {
18.                                 i.Bound(x => x.PmhDh.Levothyroxine);
19.                             })
20.                         );
21.                 })
22.                 .Sortable()
23.                 .Pageable()
24.                 .Scrollable()
25.                 .DataSource(d => d
26.                     .Ajax()
27.                     .PageSize(20)
28.                     
29.                     .ServerOperation(true)
30.                     .Read(r => r.Action("SendData", "MyAction"))
31. 
32.                 ))

I want hide columns if all cell of column was empty value and if all columns of a group was hide the column of group also hide too .

for example if Levothyroxine column data was empty string the Levothyroxine column hide and PmhDh hide too.

my problem is i have 230 columns that i must show in this grid and i want hide empty columns

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 25 Oct 2018, 08:07 AM
Hi Iman,

There is no such built-in functionality of the Grid that will hide columns based on the column's data, but you could handle the "DataBound" event of the Grid, use the "view" or "data" method of its DataSource to retrieve the items from the current view (or all items with the data method if the server operations are disabled) and if there are no values for particular column, use the hideColumn method to hide it:
Another option is to try the following approach for defining the columns of the Grid dynamically, where you could apply your custom logic initially (when the DataTable is configured):
Hope this helps.


Regards,
Konstantin Dikov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Iman
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or