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

Hiding grid columns

4 Answers 384 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Henrik
Top achievements
Rank 1
Henrik asked on 07 Jun 2016, 01:38 PM

Hi,

Whe I hide columns in a sub-grid I get problems with the look of the sub-grid. The reason seems to be that I hide the last column that does not have the width set (to make this column take up the remaining space in the row).

 

The template for the sub-grid from the cshtml page:

    <script id="utförseltemplate" type="text/x-kendo-tmpl">
        @(Html.Kendo().Grid<UtförselViewModel>()
              .Name("grid_#=Id#")
              .TableHtmlAttributes(new { @class = "ansokan-produkter-utforsel-subgrid" })
              .Columns(columns =>
              {
                  columns.Bound(p => p.Id).Hidden(true);
                  columns.Bound(p => p.UtförselDiarieNummer).Title("Diarienummer").Width(150);
                  columns.Bound(p => p.Datum).Format("{0:yyyy-MM-dd}").Title("Utförseldatum").Width(120);
                  columns.Bound(p => p.DelKvantitet).Title("Levererad kvantitet").Width(120);
                  columns.Bound(p => p.Enhet).Title("Enhet");
              })
              .Sortable()
              .DataSource(dataSource => dataSource
                  .Ajax()
                  .Read(r => r.Action("ProduktUtförslarRead", "Giltiga", new { produktId = "#=ProduktId#", ansökanProduktId = "#=Id#" }))
                  .Sort(sort => sort.Add(r => r.Datum).Descending())
              )
              .Events(events => events.DataBound("UtforslarDataBound"))
              .ToClientTemplate()
        )
    </script>

Part of the javscript ondatabound:

    if (some condition) {
        this.hideColumn(3);
        this.hideColumn(4);
    }

When I hide this column the grid looks chopped off. I guess that I need to set the column width in the javascript, but I have not been able to figure out how.
Can you help me set the column width in the javascript or set the width of the whole sub-grid?

Best regards,

Henrik

4 Answers, 1 is accepted

Sort by
0
Galin
Telerik team
answered on 08 Jun 2016, 03:30 PM
Hi Henrik,

I tried to replicate the issue which you described, but to no avail. Fore reference I am sending this video. Please, take a look at it and let me know if there are any differences at your end, which I may be leaving out.


Regards,
Galin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Henrik
Top achievements
Rank 1
answered on 09 Jun 2016, 12:20 PM

Hi, thanks for responding.

I am not sure, but I think the difference is that in my sub-grid (well, a third-level grid actually) the two columns that are left both have the width fixed in pixels (which means they can't expand to fill the whole grid width). I want to have it that way to make the columns have the same width in all sub-grids.

I am not allowed to share my code and to cut out enough code to create a running example is many hours of work, so I unfortunately can't do that.

 

Anyway, I found a workaround: I added an extra column with no fixed width, no header and no text in the rows, this makes the rows fill up the available space and the grid looks good again.

 

Best regards,

 

Henrik

0
Accepted
Galin
Telerik team
answered on 13 Jun 2016, 11:45 AM
Hi Henrik,

I am glad that you were able to solve the problem yourself. However I tried again to replicate the issue by editing the width of the columns, but to no avail.

Attached to this post you can find my test project. In case the issue persists please modify it in order to reproduce the issue on our side.


Regards,
Galin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Henrik
Top achievements
Rank 1
answered on 13 Jun 2016, 12:26 PM

Hi Galin,

 

I'd be happy to try to reproduce the error if you are interested, but the attachment contained only one cshtml-page. To see if I can reproduce the problem I need a complete project. But I am satisfied with my workaround, so only if you are interested.

 

Best regards,

Henrik

Tags
Grid
Asked by
Henrik
Top achievements
Rank 1
Answers by
Galin
Telerik team
Henrik
Top achievements
Rank 1
Share this question
or