What is the best way to assign a CSS class to the jqGrid height property when using setGridHeight?

Our objective is to implement a media query css class.

Currently, the code is utilizing $(window).height() to determine the height.

$('#list').jqGrid('setGridHeight', $(window).height() - 380);

Instead of relying on $(window).height() - 380, I am looking to integrate a css class for this purpose. Appreciate your help.

Answer №1

Here is a suggested method you can try:

// Create a hidden test div
var $testDiv = $("<div style='display:none'></div>");
$testDiv.addClass("grid_height").appendTo("body");
// Make sure you obtain the correct grid_height from the media

// Another option you can consider is
//     $("#list").addClass("grid_height");
// but make sure to do this BEFORE creating jqGrid

var height = parseInt($testDiv.css("height"), 10);
$testDiv.remove();

// You can now use the height variable to set the grid height
$("#list").jqGrid("setGridHeight", height);

UPDATE: A demo has been provided to show that this method works.

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

Adding a background color to the body of your PHP and HTML email template is a simple way to enhance

I am currently using a confirmation email template with a white background, but I want to change it to gray. However, I'm unsure how to update the PHP file containing the email function below: $headers = "From: " . stripslashes_deep( html_entity_deco ...

Encountered an error 'Unexpected token ;' while attempting to include a PHP variable in a jQuery AJAX call

Trying to execute a PHP script that updates a deleted field in the database when you drag a specific text element to a droppable area. Currently, here is the droppable area code: <div class="dropbin" id="dropbin" > <span class="fa fa-trash-o ...

Properly handling the use of single and double quotation marks in variable declarations within a JavaScript file

I have a search box where users can enter their search text. For example, they can type book, 'book', or "book". The value entered in the search box is then assigned to a variable in the JavaScript file. var searchTerm = "${searchTerm}"; <br/ ...

Looking for a carousel slider with thumbnails that allows you to customize the position of the thumbnails? Let me

I am currently using bxslider for my sliders on the website. However, I am facing an issue where the thumbnails are overlapping the main image and I am unable to adjust their position. You can check out the live site at or navigate to any gallery from t ...

Transitioning smoothly from mobile to tablet views with the sidebar activated in Semantic-UI

My HTML includes a pointing menu when the screen width exceeds 630px. Below 630px, it switches to a sidebar with a menu button: <nav class="ui inverted sidebar menu vertical slide out" id="m_menu"> <a href="index.php" ...

A guide on displaying parent and child items from an array using PHP

I am a beginner in php and I have a simple question. I want to create a parent-child view using an array with key id and key parent. How can I properly structure this in a cycle? Do I need to start by creating a function for building the tree? -Apple ...

The copyright (©) symbol is unresponsive to rotation

Why can't I rotate the © character? Am I missing something? .copy { font-size: 12px; font-family: Arial; writing-mode: vertical-rl; text-orientation: mixed; transform: rotate(180deg); } <span class="copy">&copy; This is not ...

I'm having trouble getting the modal to load automatically when the page loads. The usual bootstrap method doesn't seem to be working, and I'm

Trying to make a modal load on page load seems like a simple task, but for some reason, it just won't work! It functions perfectly fine when triggered by a click. The bootstrap and jquery scripts are included as shown below: <script src="https:/ ...

What is the best way to stack several items vertically beside an image?

As a beginner in the world of web development, I recently embarked on my first project. However, I am facing an issue where I cannot align multiple elements under each other next to an image. One element floats at the top beside the image, while the other ...

Comparing document.getElementById and the jQuery $() function

Is this: var contents = document.getElementById('contents'); The equivalent to this: var contents = $('#contents'); Considering that jQuery is present? ...

Ensure that data is not cached after the page is refreshed at regular intervals of x seconds

In the process of developing a news app, I have implemented a feature where a div with the class .new_feed is refreshed every 10 seconds to fetch new updates. However, I encountered an issue where if a new feed appears in the .new_feed div and is not cli ...

The color attribute enhances the appearance with a colored border specifically designed for Chrome users

Starting off, I appreciate the border that Chrome applies to my inputs. However, I am facing an issue with the textarea element. The problem is that the textarea uses the color attribute not only for coloring the text but also as the border color. Here is ...

Tips for rotating individual letters within a sentence on popular web browsers, including Chrome

Can you make a sentence appear with each individual letter rotating and getting larger? This is my approach: I decided to split the sentence into separate span elements, one for each letter. Then I used CSS transform -webkit-transform to animate the lette ...

What is the best way to create a layout containing a <div> split into three columns, with the middle column having rows?

I'm currently working on a <div> layout that I need to split into rows. The challenge is creating a design that is fluid and can adapt to various screen sizes, including mobile devices. While using an HTML table might be a quick fix, it's n ...

Issue with retrieving body class in Internet Explorer on Magento platform. The body class is not being recognized in IE, but works fine in Mozilla and Chrome

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>" dir="ltr"> <?php echo $this->getChildHtml('head') ?> <bod ...

The resource was identified as a document but was sent using the MIME type application/json

I'm having an issue with posting to a jQuery modal's Action and receiving JSON in return. Every time I try, I encounter the following error: Resource interpreted as Document but transferred with MIME type application/json Instead of staying on ...

Adjust column content to fit width, instead of setting width to 100%

To create columns for the ul, I used flex-direction: column and flex-wrap: wrap. When the elements within the ul are split into multiple columns, each column takes on the width of the widest content in that column. However, if there is only one column, it ...

Transition smoothly between sections using fullPage.js with clipping path effects

I am looking to create a unique clipping animation utilizing SVG clipping path. The animation should hide the first section while revealing the second section in a smooth transition using fullPage.js. This idea is somewhat similar to the question discusse ...

CodeIgniter's Comparison Feature: Like vs. Unlike

I'm looking to integrate the like and unlike functionality into a CodeIgniter project. I have successfully implemented it in normal PHP with the code below, but for some reason, it's not working in CodeIgniter. Below is the structure of my databa ...

How to use jQuery Animate to create a step-by-step animation with image sprites?

I'm working on creating an image sprite using jQuery and I'm curious if it's feasible to animate it in steps rather than a linear motion. I initially tried using CSS3 animations, but since IE9 is a requirement, the animations didn't wor ...