Define the width of jqgrid

I have been utilizing SmartAdmin jqgrid to showcase data in tabular format. The number of columns in the datatable changes dynamically each time. I am converting the DataTable to a JSON object and assigning it to the jqgrid. However, it appears that jqgrid internally sets an equal width for each column. When I hide a column from the jqgrid, it hides the column but leaves empty space on my page. I would like the jqgrid to distribute the width evenly among all visible columns.

Below is a snippet of my code:

<table id="jqgrid" style="width:100%"></table>
<div id="pjqgrid"></div>

jqgrid initialization:

            jQuery("#jqgrid").jqGrid({
            data: <% = GetJasonData %>,
            datatype: "local",
            height: 'auto',    
            colNames: jsonColname,
            colModel: <% = GetJsonColModel %>,
            rowNum: 2,
            rowList: [10, 20, 30],
            pager: '#pjqgrid',
            sortname: 'Name',
            toolbarfilter: true,
            viewrecords: true,
            sortorder: "asc",
            caption: "All Entries ",
            multiselect: true,
            shrinkToFit: true,
            autowidth: true
        });
        jQuery("#jqgrid").jqGrid('navGrid', "#pjqgrid", {
            edit: false,
            add: false,
            del: true
        });
        jQuery("#jqgrid").jqGrid('inlineNav', "#pjqgrid");
        /* Add tooltips */
        $('.navtable .ui-pg-button').tooltip({
            container: 'body'
        });

        jQuery("#m1").click(function () {
            var s;
            s = jQuery("#jqgrid").jqGrid('getGridParam', 'selarrrow');
            alert(s);
        });
        jQuery("#m1s").click(function () {
            jQuery("#jqgrid").jqGrid('setSelection', "13");
        });

        $('#jqgrid').hideCol('EFORMINSTANCEID');
        //// remove classes
        //$(".ui-jqgrid").removeClass("ui-widget ui-widget-content");
        $(".ui-jqgrid-view").children().removeClass("ui-widget-header ui-state-default");
        $(".ui-jqgrid-labels, .ui-search-toolbar").children().removeClass("ui-state-default ui-th-column ui-th-ltr");
        //$(".ui-jqgrid-pager").removeClass("ui-state-default");
        //$(".ui-jqgrid").removeClass("ui-widget-content");

        // add classes
        $(".ui-jqgrid-htable").addClass("table table-bordered table-hover");
        $(".ui-jqgrid-btable").addClass("table table-bordered table-striped");
    })

    $(window).on('resize.jqGrid', function () {
        $("#jqgrid").jqGrid('setGridWidth', $("#content").width());
    })

Where GetJasonData and GetJsonColModel contain JSON objects.

Your prompt responses will be greatly appreciated. Thank you in advance.

Answer №1

give this a shot

<div id="datatable" style="width:1250px;"></div>

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

Utilizing Smart Table for Data Binding with JSON Dataset

I need help binding a JSON file to a smart table. How can I use the loop function for iteration? The design of the smart table is displaying, but the data from the JSON file is not binding. Here is the JSON file: [ { "year": 2013, "id ...

manipulating dropdown visibility with javascript

I'm feeling a bit lost on how to structure this code. Here's what I need: I have 5 dropdown boxes, with the first one being constant and the rest hidden initially. Depending on the option chosen in the first dropdown, I want to display the corres ...

The TableView appears to be selectively skipping over certain cells in order to present data sourced from

After successfully parsing the JSON data, I faced an issue when trying to display it in a TableView. The problem was that only certain rows were being displayed, such as the first row followed by the sixth and so on. You can see the issue here: This is ho ...

Guidelines for forming a JSON variable using a SOAP Response

Currently using ASP.NET 4.0, I am faced with the task of sending a SOAP (XML) Response to a JSON variable in javascript on the page. The aim is to access the variable and its properties just like any other JSON variable would be accessed. The challenge lie ...

Even after setting the handler to return false, Angular continues to submit the form

In the following scenario, I have encountered an issue: Here is the HTML template snippet: <form [action]='endpoint' method="post" target="my_iframe" #confirmForm (ngSubmit)="submitConfirmation()"> <button type="submit" (click)="conf ...

Implementing jQuery to showcase an element on the screen

I would like to express my gratitude to everyone who has helped me. Please forgive my poor English :) Can someone provide me with a jQuery script that can extract the name of the currently selected tab and display it in an h1 tag? Whenever the selected ta ...

What is the best way to position my logo on top of the stunning space background?

Click here to check out the code on CodePen Please take a look at my code on codepen.io. I am new to Stack Overflow so please be patient with me if I make any mistakes. ;-; I currently have my logo (https://i.stack.imgur.com/W0nWc.png) included in the co ...

The Navbar is not displaying the React Bootstrap 4 CSS module as intended

Having some trouble changing the color of my navbar. Is there a step I might be missing? Here's the component I'm trying to render: import React from 'react'; import { Nav, Navbar } from 'react-bootstrap'; import styles from ...

Developing a custom CSS for React using clamp and focus attributes

I'm currently working on creating an object to be used in inline style, but I'm having trouble figuring out how to correctly write `clamp` and `after`. const PhoneInputStyle = { fontSize: clamp("13px", "1.111vw", "16px"), /*this particular ...

Steer clear of retrieving all the elements from the HTML DOM at once

Scenario I am working on a HTML5+CSS+JS slideshow project that needs to be synchronized across 50 clients in a local area network using a single wireless router. Challenge Due to the heavy content, particularly images, of the slides, I intend to dynamic ...

What is the best way to choose a single li element?

I am working on creating a reservation system using HTML, CSS, and JS. I want to customize the color of the border for each list item (li). However, I want only one li to be selected at a time. When I click on a different li, it should remove the selection ...

Having trouble processing JSON object within Flask Jinja template

Upon examining a straightforward JSON dataset: {"thisdata": ["/home/fyp/Desktop/AVA/AVA-STORAGE", "Network has already been configured since nexpose-pc is in virtualbox! ...", "/home/fyp/Desktop/AVA/AVA-APP/RunGUI", "ubuntu-trusty\t192.168.0.21", "", ...

Ensuring that two operators are not consecutively placed in a Javascript calculator-validation guide

After creating a basic calculator using HTML, CSS, and JavaScript, I encountered an issue. When validating user input, the calculator currently accepts multiple operators in a row. To address this, I attempted to prevent consecutive operators by checking ...

How to Align the Button Vertically with the TextField in React Material-UI

Utilizing the Material-UI library for React, I have been working on creating a simple form with the following design: https://i.stack.imgur.com/LY3ZN.png My challenge lies in aligning the button with the TextField element. Adjusting the margin-top proper ...

Loading local JSON data using Select2 with multiple keys can greatly enhance the functionality

Comparing the select2 examples, it is evident that the "loading remote data" example contains more information in the response json compared to the "loading array data" example. I am interested in knowing if it is feasible to load a local json file with a ...

Optimal ffmpeg configurations for encoding videos into mp4 and ogg formats for seamless playback on HTML5 platforms

Despite the buzz surrounding it, the HTML5 video tag is facing a minor issue. To ensure cross-browser compatibility, multiple video formats - like mp4 and ogg - need to be included for its use. Unfortunately, I couldn't find optimal settings for each ...

Tips on converting a JSON array into a strongly-typed C# class instance via deserialization

This question seems quite similar to another one posted here. Despite my efforts to convert the provided solution into C#, I am not a JSON expert and find myself confused. The challenge lies in deserializing the JSON response from the Kraken OHLC endpoin ...

What steps should I take to craft an SQL command that retrieves the data, specifically an image, stored within a JSON

JSON Object {"images": ["https://unique-example.com/image.jpg"], "remarks": "completed", "documentList": [{"id": "GST", "value": "Goods and Services Tax"}]} sele ...

Is it possible for me to add some PHP code to the action of a form?

Within a foreach loop, I have the following code that lists unique codes as links: <a href="" class="charcoal_link" style="line-height: 20px;" onclick="showMessageArea(this); return false;" > <?php echo $uniqueCode1?><span class="pink_tex ...

What is the best way to modify the text color in an MUI Text Field?

I'm completely new to using MUI and React, and I've run into an issue with changing the text color in my input field. Even though I specified inputProps={{sx: { color: "CCCCCC" }}}, the text color remains black while the label and searc ...