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

Kendo Grid Width and Height Confusion

7 Answers 3953 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adrian
Top achievements
Rank 1
Adrian asked on 27 Jul 2012, 10:34 PM
So I've got a Kendo Grid initialized like so:
var custData = {
    "columns": [
        { "field": "ID", "title": "ID", "filterable": true, "width": 1 },
        { "field": "Last", "title": "Last", "filterable": true, "width": 1 },
        { "field": "Middle", "title": "Middle", "filterable": true, "width": 12 },
        { "field": "First", "title": "First", "filterable": true, "width": 1 },
        { "field": "Role", "title": "Role", "filterable": true, "width": 1 },
        { "field": "Rank", "title": "Rank", "filterable": true, "width": 1 }
    ],
    "data": [/* Lots of data here, organized like so: */
        { "ID": "00011", "Last": "Picard", "Middle": "", "First": "Jean Luc", "Role": "Commanding Officer", "Rank": "Captain" }
    ]
};
var custDataSource = new kendo.data.DataSource({
    pageSize: 10,
    data: custData["data"]
});
$("#customers").kendoGrid({
    height: 600,
    width: 800,
    columns: custData["columns"],
    dataSource: custDataSource,
    groupable: true,
    scrollable: false,
    sortable: {
        mode: "multiple",
        allowUnsort: true
    },
    pageable: true,
    selectable: "multiple row",
    nagivatable: true,
    toolbar: [
        { name: "create", text: "New" },
        { name: "save", text: "Save" },
        { name: "cancel", text: "Cancel" },
        { name: "destroy", text: "Delete" }
    ],
    editable: {
        update: true,
        destroy: false,
        confirmation: "Are you sure you want to remove this item?"
    }
});

I'm trying to get a grid with a static height and width. It absolutely must not change height and width when I page (which it currently does, due to variably-sized data). The same is true of the data cells. They absolutely must not change size or shape, but they do anyway. I tried setting static width and height, but it seems to be ignoring them to some degree. Beyond that, the column widths are not defining the widths of the columns, but rather the number of pixels to add to the width of the column. Also, it doesn't actually add the specified number of pixels, but some seemingly arbitrary number any given time.

When there's too much data in a cell, it wraps, making the row taller, and thus changing the height of the Grid. That is unacceptable. I require a static height and width, and perhaps it could show the full contained value of the cell on mouseover. I need the values to not wrap or overflow in any way. Is there some way to achieve this?

When paging, the column widths change, throwing off the data alignment. It just looks bad, visually, to be paging through the data, and seeing the column widths changing (and the height of the Grid changing in response to taller rows, too).

Things I need to accomplish, broken out into a list:
  • Static column or cell widths
  • No wrapping of cell content, and no resulting overflow either (white-space: nowrap; overflow: hidden;)
  • Static row or cell heights
  • Static overall Grid height (cannot have scrolling Grids, because may be viewed on mobile platform where scrolling in child containers does not function)
How can I achieve those goals without too much hackery? I'm willing to add a CSS style to address the cell overflow and wrapping issues if necessary, but how about the column/cell widths and row/cell heights? I'm sure that the overall height issue will resolve itself once my rows stop changing height.

Thank you.

Best Regards,

Adrian

7 Answers, 1 is accepted

Sort by
0
Adrian
Top achievements
Rank 1
answered on 30 Jul 2012, 08:57 PM
Ok, so I tried ensuring that all cells have
white-space: nowrap
and
overflow:hidden
applied to them. The rules propagated fine. Now I have another problem, related to the column width control, or lack thereof. The cells now stretch in width to accommodate the content which now has white-space wrapping disabled. Because the column widths are not being honoured, the overflow rule doesn't have a chance to become effective.

Looking into the code generated by the Grid plugin, it appears to be using a colgroup, which should be fine, but appears to be ignored by the table cells. I tried modifying the grid plugin code (difficult with the obfuscation, but not impossible) to just create a <tr /> with a CSS class that gives it 0px height, and applying the specified widths as CSS width values to the child <td />. I apparently did it wrong, because it no longer generated a <colgroup />, but it also didn't generate the <tr class="colgroup" /> that I told it to.

There is a silver lining to this cloud, though. To get the <tr /> <td /> method to work, one must include a rule in the table's CSS:
table-layout: fixed
and doing so fixed the problem with the <colgroup /> widths not being honoured.

So this gives me an idea for a feature/modification suggestion: add
table-layout: fixed
to the KendoUI Grid plugin's CSS file, or else the widths set in the initial Grid declaration will be ignored.

It still doesn't work perfectly; the widths seem to be proportional rather then absolute (setting the column width to "1" makes it standard width, 2 makes it slightly wider, etc.). I'm not really sure why this is, but it's a lot better than it used to be without table-layout specified in the table's CSS. I still don't consider it fixed, but it is at least functional now.
0
Dimo
Telerik team
answered on 31 Jul 2012, 03:19 PM
Hello Adrian,

The currently set column widths are invalid, so the browser ignores them and expands the columns proportionately. You can't have a sum of column widths, that does not match the width of the Grid table. You can remove at least one column width and set some reasonable numbers to the other columns.

In otrder to prohibit the browser from resizing columns at its own discretion, you should apply a table-layout:fixed style to the Grid table, as you have already observed. This is done automatically when scrolling is enabled, but as far as I can see, you have disabled it. We prefer not to set fixed layout to scroll-less Grids, because this is not the default <table> state.

Using table-layout fixed will ensure that table cells do not expand horizontally, but there is no way to prevent them from expanding vertically, unless you use column templates and insert all data into <div>s with explicit height and an overflow:hidden style applied.

Regards,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Adrian
Top achievements
Rank 1
answered on 31 Jul 2012, 03:45 PM
Thanks for the information. I was under the impression that I could only set column widths to a standard integer value, which would be concatenated with a "px" and applied to the width style on the <col /> tag. I tried, on a whim, entering my widths as percentages, in quotes, and the Grid plugin accepted these just fine. Now I have a grid with a fluid width, static height, and
.k-grid td {
    white-space: nowrap;
    overflow: hidden;
}
 
.k-grid table {
    table-layout: fixed;
}

This is working well for me at the moment.

The reason I'm not using scrolling (though I would very much like to) is because the web application I'm working on is based on Twitter's Bootstrap responsive CSS framework, and needs to be displayed on mobile devices. As a result, paging is required to ensure that all records can be viewed from a mobile device (scrolling in child elements on a mobile browser does not work without lots of additional workarounds). I may plan on making scrolling conditional so it only occurs on desktop browsers, and paging is automatically enabled on mobile devices, but that's neither here nor there. I needed the grids to be of fluid width so they can respond properly to the layout, which will be placing multiple Grid-based data "widgets" in parallel on the same page, to display various different data types relating to a master project (the page being designed currently is a project information page). These widgets may have as few as three columns or as many as ten (and as few as zero records or as many as a few hundred), and may take up anywhere from one-third of the page width to the entire page width (but must remain of static height, which is still a problem when grouping by column header, but I will figure out a workaround for that on my own time -- perhaps by only allowing grouping when scrolling is also enabled, and therefore only on desktop browsers).

Additionally, I would like to point out (both for everyone's reference, and by way of trying to rectify the issue) that some of the information relating to the settings for the Grid plugin were not available in the documentation (and here), but had to be gathered also from some of the demos and a forum thread or two as well. I would also like to express my interest in having al lthe localization (strings, etc.) either exposed through the settings in the API, or (possibly and) accessible via a central localization file.
0
Dimo
Telerik team
answered on 01 Aug 2012, 09:06 AM
Hello Adrian,

Based on the provided information, I can also suggest you another option to try out - percentage column widths combined with a min-width style for the Grid table.

Indeed, there are some things missing from the documentation, but updating it is an ongoing task.

Greetings,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Roger
Top achievements
Rank 1
answered on 01 Aug 2012, 11:56 PM
Based on the provided information, I can also suggest you another option to try out - percentage column widths combined with a min-width style for the Grid table. 

Can you describe what you mean by percentage column widths?  I don't see anything in the documentation, samples, or source code that indicate that this is available.

Thanks
roger
0
Dimo
Telerik team
answered on 02 Aug 2012, 08:15 AM
Hello Roger,

columns: [{
    field: "FirstName",
    width: "20%",
    title: "First Name"
}]


Regards,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Adrian
Top achievements
Rank 1
answered on 02 Aug 2012, 03:00 PM
The percentage column widths and a min-width rule have helped immensely with keeping the grid and its columns at a favourable size and shape in my layout. The percentage widths were a stroke of luck, as the documentation seemed to imply that raw numerical values were to be entered, and did not specify that a "px" or "%" value could be entered. In addition, telling the buttons that they can have a min-width of 0px and replacing the text with a blank space has been helpful in ensuring the toolbar buttons don't wrap to a second line either (though I could easily replace the buttons using a template containing an <img /> tag, but I haven't gotten there yet. While I'm on the subject: is there a way to replace the filter icon in the column headers, similar to using a template for the button contents? I have a set of icons I would like to use, if possible, but they're black, and the filter icon is grey. I suppose I *could* just dig into the files and swap the image file, but if there's a way to do it programmatically, I would prefer that.

So far, here's my CSS:
div[class^="span"] {
    min-width: 320px;
}
 
.k-grid td {
    white-space: nowrap;
    overflow: hidden;
}
 
.k-grid table {
    table-layout: fixed;
}
 
.k-grid tbody .k-button {
    min-width: 0px;
}

...and here's my Grid initialization:
var kendoGridFilterable = {
    name: "FilterMenu",
    extra: true
}, kendoGridPageable = {
    pageSize: 10,
    previousNext: true,
    numeric: false,
    info: true
}, kendoGridToolbar = [
    { name: "create", text: " " },
    { name: "edit", text: " " },
    { name: "destroy", text: " " },
    { name: "save", text: " " },
    { name: "cancel", text: " " }
];
 
$("#gridOne").kendoGrid({
    columns: dataOne["columns"],
    dataSource: dataOneSource,
    groupable: true,
    scrollable: false,
    reorderable: true,
    resizable: true,
    sortable: {
        mode: "multiple",
        allowUnsort: true
    },
    filterable: kendoGridFilterable,
    pageable: kendoGridPageable,
    selectable: "row",
    nagivatable: true,
    toolbar: kendoGridToolbar,
    dataBound: function () {
        //checks if there are any groups
        if (this.dataSource.group().length == 0) {
            //changes the text of the grouping template
            setTimeout(function () {
                $(".k-grouping-header").html("Drag column header here to group");
            });
        }
    }
});
The grid expands to fit the container element I placed it within, and when Bootstrap's responsive CSS changes the layout to fit smaller screens, the table remains usable and undistorted, with no wrapping occurring.
Tags
Grid
Asked by
Adrian
Top achievements
Rank 1
Answers by
Adrian
Top achievements
Rank 1
Dimo
Telerik team
Roger
Top achievements
Rank 1
Share this question
or