Setting Kendo grid height to a specific value upon page load

Looking to achieve a fixed height and width for a Kendo grid, regardless of data size. Scrolling should be enabled if data exceeds the fixed dimensions.

The issue arises when the page initially loads with data, as the Kendo grid does not adhere to the specified fixed height and width. However, resizing the window causes the grid to conform to these dimensions and provide a scroll option within.

How can I ensure that the Kendo Grid maintains a fixed height upon initial loading?

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>

Answer №1

Solution to the problem:

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

To resolve the issue, include this code snippet in the Kendo grid script. This will adjust the height of the grid dynamically after the Data Bound event, allowing customization of the grid's CSS properties.

Answer №2

My approach is dynamic, adjusting the Grid to occupy 100% of the screen excluding the 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" accounts for the two 1px borders at the top and bottom.

Answer №3

I believe using this method provides a more dependable solution that can also accommodate locked or frozen columns. When the window is resized, you can include these lines of code in the event handler:

var availableHeight = 500; // Determine this value by considering the space within the grid's parent container 
$('#YOUR_GRID_ID').data('kendoGrid').setOptions({ height:  availableHeight})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for eliminating the gap between Bootstrap 4 columns

Is there a way to eliminate the spacing between Bootstrap columns? I have three columns set up using Bootstrap but no matter what I do, I can't seem to get rid of the space between them. <!doctype html> <html lang="en> <head> ...

Combining php with jquery

This message contains a successful integration of PHP code within jQuery using the AJAX method. However, there are errors encountered which may be due to my lack of experience in jQuery. Uncaught ReferenceError: save_customer is not defined Uncaught Synt ...

Indicate the end of the row in JavaScript when using the match() function

What's the best way to identify the end of a row when using the match() function? I'm trying to extract "2021 JANUARY 18 MONDAY" from this page. https://i.sstatic.net/bTNdQ.png https://i.sstatic.net/YzFs2.png If there is additional text after ...

Change the input, update the price in the division

I am currently working on implementing a simple cart update feature that involves changing the total price and quantity, leading to an automatic price update. While attempting this task, I encountered a challenge that I'm struggling to solve. Although ...

axios in node does not support relative URLs

When running my node server, the code below works just fine axios.get('http://localhost:8080/myPath') // works Unfortunately, using relative paths does not work axios.get('/myPath') // doesn't work This is the error I encounter ...

What is the best method for converting a plist file into a json file?

Is there a way to convert an existing plist file into a JSON file using one of the following programming languages: JavaScript, Java, Objective-C, Python, or Ruby? Any suggestions on how to do this? ...

Using JS to switch between text and state in ToneJS

I am facing an issue with the text not displaying in the "play-stop-toggle" element, despite my limited experience with JS. My desired outcome includes: [SOLVED] The text in <div id="play-stop-toggle" onclick="togglePlay()">Play ...

What is the best way to imitate a DOM in order to effectively test a Vue application with Jest that incorporates Xterm.js?

I've created a Vue component that displays an Xterm.js terminal. Terminal.vue <template> <div id="terminal"></div> </template> <script> import Vue from 'vue'; import { Terminal } from 'xterm/lib/public ...

Is there a way to use jQuery to adjust the text color once it has been clicked on?

I have been struggling to change the text color upon clicking on it without any success. Within my code, there are seven labels - one for the question, four for the answer options, one for the correct answer, and the last one for the explanation. The desi ...

Return an array with only emails included

Looking to sort through an array specifically for emails, I attempted the following action emails = emails.filter((x)=>(x !== (undefined || null || ''))) To remove any empty values, while still allowing non-email values. ...

Consider creating a distinct document for your "scripts"

Within my package.json configuration file, the "scripts" section contains numerous commands structured as shown below. "scripts" { "script1": "command example", "script2": "command example", "script3": "command example", "script4": "command exampl ...

Using Bricklayer.js multiple times on one page: a guide

UPDATE I have incorporated @Alice's solution into this code snippet to demonstrate the purpose of using bricklayer. While working with bricklayer, I noticed that it only affects the first bricklayer and ignores the second one. This behavior is expecte ...

Changing the name of a radio button dynamically using jQuery

Trying to find a solution like the following: $("input:radio:checked").previous("name", "original_name").attr("name","new_name"); I've experimented with a few methods found here, but keep encountering the error: Object Expected Any assistance would ...

Unable to retrieve the value of the concealed tag

Here's the code I'm working with: <html> <head> <script type="text/javascript"> var x = document.getElementById("2").value; document.getElementById("1").innerHtml = x; </script> </head> <bo ...

Unveiling the Secret: Removing Duplicate Elements from an Array

I'm attempting to create a JavaScript function that can remove duplicates from an array without using the Set, filter, or reduce functions. I've tried using nested loops to compare elements and splice duplicates out of the array, but I seem to be ...

What are the steps for building modules using Vuex and fetching data using mapState()?

I've been experimenting with separating my Vuex code into modules, but I'm having trouble retrieving data using mapState(). What's the most effective approach for creating modules and utilizing mapping? Here's the structure of my stor ...

Should I manually unbind the angular.js $destroy event?

Is it automatically unbinding watchers and scope events that are bound with $scope.$on(...) or $scope.$watch(...) when the scope is destroyed in Angular? Let's consider the following code: $scope.$on('someEvents', handleSomeEvent); $scope. ...

How can I transfer an image from the clipboard onto a fabric.js canvas?

I am currently working on developing a function that will allow users to paste an image from their clipboard onto a canvas as a new fabric.Image(). However, every search result I come across either discusses cloning existing objects within the canvas or pa ...

Retrieve the chosen identification from a dropdown menu (select box) with jQuery

I've been on a quest to find a solution for extracting the id from a selected option in a dropdown list. After extensive research, I stumbled upon this helpful resource: Get selected text from a drop-down list (select box) using jQuery I attempted t ...

The Google Picker API encounters a server error when attempting to retrieve the OAuth token after being released as a private add-on

Recently, I encountered a puzzling issue with my script that utilizes the Google Picker API. During testing, everything worked flawlessly until I decided to publish it as a private add-on. From that point on, the script's getOAuthToken function starte ...