Kendo grid not respecting css width set

1 Answer 10 Views
Grid
Benjamin
Top achievements
Rank 1
Iron
Veteran
Benjamin asked on 20 Jun 2022, 09:29 AM | edited on 20 Jun 2022, 09:38 AM

i have set my th with style="width:240px !important;".

but when the table get render, the actual width of the cell get shrink to 180px. 

kendo grid seems to be trying to shrink the table to fit into the container.

 

my js to render kendo grid is


 $(document).ready(function() {
            $("#kendo-table").kendoGrid({
                sortable: true,
                scrollable: false,
                sort: function(e) {
                    // Prevent the default behavior.
                    e.preventDefault();
                    // Check which column is being sorted. We only need to change the sorting behavior for the first column(the one with the link).
                    let field = e.sort.field;

                    if (field == "link") {
                        // Specify a custom compare function
                        e.sort.compare = function(a, b, desc) {
                            // Extract only the part between <a></a>.
                            let aNoHref = a.link.trim().match(/<a [^>]+>([^<]+)<\/a>/)[1];
                            let bNoHref = b.link.trim().match(/<a [^>]+>([^<]+)<\/a>/)[1]
                            // Compare the two values.
                            return aNoHref.localeCompare(bNoHref);
                        }
                    }
                    // Sort the dataSource manually.
                    this.dataSource.sort(e.sort);
                },
                pageable: {
                    pageSizes: false,
                    messages: {
                        display: "" // set it to an empty string
                    }
                }
            });

            $("#kendo-table").data("kendoGrid").dataSource.pageSize(10);
        });
i have set scrollable to false, is due to not wanting to have the thead inside a table tag while the tbody in another table tag

1 Answer, 1 is accepted

Sort by
0
Georgi Denchev
Telerik team
answered on 22 Jun 2022, 02:10 PM

Hi, Benjamin,

When the Grid is initialized from an existing <table> element, the column widths must be specified on the <col> element:

    <table id="kendo-table">
      <colgroup>
        <col />
        <col style="width:340px" />
        <col style="width:120px"/>
        <col />
        <col />
      </colgroup>
      <thead>

Best Regards,
Georgi Denchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
Benjamin
Top achievements
Rank 1
Iron
Veteran
Answers by
Georgi Denchev
Telerik team
Share this question
or