Hiding grid columns

5 posts, 1 answers
  1. Henrik
    Henrik avatar
    11 posts
    Member since:
    Nov 2015

    Posted 07 Jun Link to this post

    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

  2. Galin
    Admin
    Galin avatar
    526 posts

    Posted 08 Jun Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Henrik
    Henrik avatar
    11 posts
    Member since:
    Nov 2015

    Posted 09 Jun in reply to Galin Link to this post

    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

  5. Answer
    Galin
    Admin
    Galin avatar
    526 posts

    Posted 13 Jun Link to this post

    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
  6. Henrik
    Henrik avatar
    11 posts
    Member since:
    Nov 2015

    Posted 13 Jun Link to this post

    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

Back to Top
UI for ASP.NET MVC is VS 2017 Ready