Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Set Kendo grid height to a fixed value on page load

I am trying to get a Kendo 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). If data increases ,I should provide the Scrolling.

The problem is that when the page is first loading with Data the kendo grid is not setting to that fixed height and width. but if I resize the window it is getting that fixed height and Providing the Scroll option inside Kendo Grid

So I can I set the height Of kendo Grid at a fixed value when it loads for first time

Kendo Version : v2014.1.318

Code:

$("#ViewUnitContainerTracking").kendoGrid({
                        sortable: true,
                        height:"280px",

                        columns: [
                            {
                                field: "UnitCode",
                                title: "Unit",
                                width: "15%"
                            },

                             {
                                 field: "UnitName",
                                 title: "Unit Name",
                                 width: "35%"
                             },

                            {
                                field: "Status",
                                title: "St",
                                width: "5%",
                                template: $("#TemplateViewUnitTrackingStatus").text()
                            },

                             {
                                 field: "StartDate",
                                 title: "Start Date",
                                 //template: $("#TemplateViewUnitTrackingStartDate").text(),
                                 width: "15%",
                                 //type: "date"
                             },

                              {
                                  field: "EndDate",
                                  title: "End Date",
                                  //template: $("#TemplateViewUnitTrackingEndDate").text(),
                                  width: "15%",
                                  //type: "date"
                              },

                             {
                                 field: "AssessPrgress",
                                 title: "%OAP",
                                 width: "10%"
                             },
                             {
                                 field: "Status",
                                 title: "Status",
                                 hidden: true
                             }

                        ],
                        editable: false,
                        resizable: false,
                        mobile: true,
                        dataSource: data.UnitList
                    });

Html Page:

<div id="ViewUnitContainerTracking" style="padding-top:10px;">
</div>
like image 935
bhakti Avatar asked Sep 25 '14 09:09

bhakti


People also ask

How do I set data for Kendo grid?

Bind data to Kendo Grid by using AJAX Read action method. Change the datasource on change event of any HTML controls. Normally, a developer can bind the data to Grid by using AJAX Read method. This read method is ActionResult method in MVC which will return JSON DataSourceResult & direclty bind the data to Grid.

What is dataItem in kendo grid?

Returns the data item to which the specified table row is bound. The data item is a Kendo UI Model instance.

What is Databound event in kendo grid?

Fired when the widget is bound to data from its data source. The event handler function context (available via the this keyword) will be set to the widget instance.


2 Answers

Answer of the problem is:-

dataBound: function() {
    $('#ViewUnitContainerTracking .k-grid-content').height(280);
}

Adding this to the Kendo grid will Solve the issue. As After Data Bound event we can set the custom Css property of the Grid as the Grid dynamic height is set previous to this event.

like image 185
bhakti Avatar answered Nov 15 '22 01:11

bhakti


I m doing this dynamically, to set the Grid to 100%, means, minus bootstrap header and footer:

<script type="text/javascript">
    var gridElement = $("#serviceGrid");    
    function resizeGrid() {
        $("#serviceGrid").css("height", $(window).height() - $("#itheader").height() - $("#itfooter").height() - 2);
        gridElement.data("kendoGrid").resize();
    }    
    $(window).resize(function() {
        resizeGrid();
    });
</script>

The "- 2" is because of two 1px borders a top and bottom..

like image 28
florian.isopp Avatar answered Nov 14 '22 23:11

florian.isopp