Tips for increasing the height of a Kendo-UI grid to 100% within an AngularJS 1.x environment

Encountering an issue, I needed a Kendo UI Grid widget with its height set to 100% of the surrounding <div>. Attempting basic CSS styling on the grid proved unsuccessful:

html, body {
    height:100%;
}
.expand-vertical {
    height: 100%;
    min-height: 100%
}
<div ng-app="app" ng-controller="demoController as vm" class="expand-vertical">
    <kendo-grid k-options="vm.gridOptions" class="expand-vertical"></kendo-grid>
</div>

View the results in this fiddle, which works well until window resizing is involved.

Research led me to a jQuery solution provided in an answer to a similar question, but it didn't cover the angular approach. The question remains open on how to achieve this behavior elegantly in AngularJS.

Answer №1

If you're wondering where to hide code that manipulates the DOM in AngularJS 1.x, the answer lies in using a directive. As per the AngularJS documentation:

Directives are essentially markers on a DOM element (could be an attribute, element name, comment, or CSS class) that instruct AngularJS's HTML compiler ($compile) to add a specific behavior to that element or even modify the element along with its children.

This means you can create your own directive to implement the desired resizing functionality to your grid:

// Directive definition with angularJS dependency injection
// for the $window object.
app.directive('expandKGrid', ['$window', function ($window) {

    // Define the directive, allowing use only as 
    var directive = {
        link: link,           // Function that applies the behavior
        restrict: 'A',        // Attribute-only directive restriction
        require: 'kendoGrid', // Directive must be set on a <kendo-grid> element
    };
    return directive;


    function link(scope, element, attrs) {
        var gridElement = $(element);

        // Add an event handler to resize the data area of the grid
        // when the window is resized
        $($window).resize(function () {
            // Select the element containing the data
            var dataElement = gridElement.find('.k-grid-content');
            // Exclude non-data elements like headers and footers
            var nonDataElements = gridElement.children().not('.k-grid-content');
            // Calculate the height of the grid excluding any borders or margins
            var currentGridHeight = gridElement.innerHeight();
            // Determine and set the height for the data area
            var nonDataElementsHeight = 0;
            nonDataElements.each(function () {
                nonDataElementsHeight += $(this).outerHeight();
            });
            dataElement.height(currentGridHeight - nonDataElementsHeight);
        });
    }
}]);

Apply this directive to your grid like so:

<div ng-app="app" ng-controller="demoController as vm" class="expand-vertical">
    <kendo-grid k-options="vm.gridOptions" expand-k-grid class="expand-vertical">
    </kendo-grid>
</div>

By combining the existing CSS with the AngularJS directive, the grid will always maintain a height of 100% within its container, even during window resizes:

You can check out how this works in action by visiting this fiddle.

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

Update the ngModel value once input validation has been successfully validated

My input is defined as shown below <input id="xInputControl" name="xInputControl" type="text" xInput class="form-control" [(ngModel)]="x" #validated="ng ...

How to Utilize AngularJS to Interact with Play 2 REST API Despite CORS Challenges

I am currently working on an AngularJS application that interacts with a REST API built using Play Framework 2.2.0. One issue I've encountered involves cross-domain ajax calls, since the Angular and Play applications are not hosted on the same domain ...

How can you use a jQuery Selector to target all images and sources within dynamic containers?

I am currently attempting to identify all images and their paths (srcs) within the dynamic containers. The dynamic containers refer to container patterns stored in an array, which is filled dynamically. For example: var containers = new Array( ...

CORS policy blocked Deepl API request

For the past few months, I successfully integrated Deepl API into our Web CRM. However, things took a turn a few days ago. I can't pinpoint exactly when, but it might have been since the start of the new year. Now, every request is being blocked by s ...

Processing a JSON array of objects in AngularJS

When using Angular's fromJson function to parse a JSON string, I encountered an issue. If the JSON is a simple array like "[1, 2]", the code works fine. However, I need to work with an array of dictionaries instead. var str = "[{'title' ...

Having difficulty with Angular's ng-options feature in a Select element

I'm currently tackling an issue with using ng-options to iterate through an array of objects and display specific properties in a select element. Upon querying the api/admin endpoint, I receive JSON data containing details of all users holding the ad ...

Troubleshooting issue with parsing MySQL data in HTML table using Node.js

Seeking Assistance! I am currently in the process of developing a node file that displays data from MySQL on an HTML page with a search bar. My issue is that sometimes when I run the code, enter something into the search bar and hit the button, it works s ...

One-time execution of timed event

I'm struggling to get this function working properly. In my system, users can approve or disapprove a post by clicking on a link. All the content is loaded using ajax calls. When a user clicks, an alert pops up indicating success or error and then r ...

When a client sends a GET request to the server, an error occurs due to the absence of 'Access-Control-Allow-Origin' header in

I am encountering an issue with my node/express js application running on localhost while making a 'GET' request to Instagram's api. The error message I keep receiving is: XMLHttpRequest cannot load https://api.instagram.com/oauth/authorize ...

Extracting data from JSON response

The JSON output is as follows: [{"Post":{"name":"Name1","text":"Text1"}}, {"Post":{"name":"Name2","text":"Text2"}}] In attempting to retrieve the values, I used the following code: var data = $.parseJSON(result) // converting JSON to object I tried acc ...

"Troubleshooting AngularJS UI Bootstrap Typeahead: How to Fix the Issue

Here is my HTML code snippet: <p> <input type="text" ng-model="destination" placeholder="Destination" uib-typeahead="dest as dest.name for dest in fetchDestinations($viewValue)" typeahead-loading="loadingDestinations" typeahea ...

The click functionality appears to be malfunctioning

I encountered an issue with my code related to the click events. The problem is that one click event doesn't work after another one. Here is my ajax and jquery code: <!-- Placeholder for confirmation modal when gevonden button is clicked, then u ...

Utilize Google Maps in jQuery to visualize the distance between two points by inputting the names of the cities or counties

I am in need of creating a map that includes a starting point marked as A and an end point marked as B using Google Maps. Currently, my database stores the names of Regions/Counties as strings rather than geolocation data (longitude and latitude). Is it fe ...

Issue encountered while integrating Angular with Grails

Below is the content of my index.gsp file <!DOCTYPE html> <html ng-app="myApp"> <head> <title>my app</title> </head> <body> <input type="text" data-ng-model="test"/> {{test}} </body> <script src ...

Display a modal before leaving the page?

I need to display a modal message when a user navigates away from the page, triggered by a successful AJAX call. The issue is that if the message loads too quickly, the user may not have enough time to read it before being directed to another page. This is ...

Stop the running of JavaScript in Internet Explorer 6

I am looking for advice on how to prevent certain parts of my JavaScript code (using jQuery) from running in IE6. Can anyone recommend the best methods to achieve this? Appreciate any help you can provide, thank you! ...

The day text function failed to return a value and instead gave back

I am having trouble figuring out where the mistake is in my function below. My goal is to retrieve the day value in string format. function getDayText(date){ var weekday = new Array(7); weekday[0]= "Sunday"; weekday[1] = "Monda ...

The formValidation, previously known as BootstrapValidator, is causing issues with my form submission via Ajax, despite my efforts to update the code to work with

I recently upgraded the old BootstrapValidator to the new 0.6.0 release known as formValidation. Despite reading the documentation multiple times, I have been unsuccessful in finding the issue and need some assistance. Below are the CSS styles and scripts ...

Ajax sending numerous requests to the API

Recently, I began my journey of learning Javascript and decided to interact with my Django API through Ajax requests. To achieve this, I created a search bar that triggers the API call after a one-second delay following a keyup action. input.addEventListe ...

Randomize.js feature following the completion of an asynchronous request

I recently started using a library called Shuffle, which can be found at . It works well for me, but I am currently facing an issue with implementing a load more button to load additional images. The functionality is based on Ajax, however, after making t ...