How to extract information from SQL Server and display it in Jqgrid

I successfully created a table using datatable with the following code:

<table id="display" class="display" width="100%" data-search="true"></table>
<script src="//cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
<script src="//cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css"></script>
<script>
    $(document).ready(function () {
        var data = JSON.parse('@DATA_QUERIED');
        var keys = Object.keys(data[0]);
        var columns = [];
        for (var k in keys) {
            columns.push({

                'title': keys[k],
                'data': keys[k],
                'targets': k,
                'width': 60
            });
        }
        $('#display').DataTable({
            'data': data,
            'columns': columns,
            'searching': true,
            "paging": true,
            "ordering": true,
            "info": true
        });
    });
</script>

Now, I am wondering how to achieve the same result using jqGrid. Here is my attempt:

<table id="list5"></table>
<div id="paper5"></div>
<script>
    $(document).ready(function () {
        jQuery("#list5").jqGrid({
            datatype: "json",
            data: "{}",
            colModel: [
                { name: 'USER_ID', index: 'USER_ID', width: 100 },
                { name: 'USER_NAME', index: 'USER_NAME', width: 140 },
                { name: 'LOGIN_NAME', index: 'LOGIN_NAME', width: 140 },
                { name: 'PASSWORD', index: 'PASSWORD', width: 140, align: "right" },
                { name: 'DESCRIPTION', index: 'DESCRIPTION', width: 140, align: "right" },
                { name: 'GROPU_ID', index: 'ROPU_ID', width: 140, align: "right" },
                { name: 'EMAIL', index: 'EMAIL', width: 200, sortable: false },
                { name: 'ACTIVE', index: 'ACTIVE', width: 50 },
                { name: 'ORGANIZATION_ID', index: 'RGANIZATION_IDz', width: 140}
            ],
                paper:"lits5",
                rowNum: 10,
                rowList: [10, 20, 30],
                pager: '#pager5',
                sortname: 'USER_ID',
            viewrecords: true,
            sortorder: "desc",
            caption: "Simple data manipulation",
          
        })
        jQuery("#list5").jqGrid('navGrid','#paper5',{edit:false,add:false,del:false});
    });
</script>

Next, I have an SQL query as follows:

SECLECT * 
FROM sec_log

To parse this data, I use the following code snippet:

var data = JSON.parse('@DATA_QUERIED');
var keys = Object.keys(data[0]);
var columns = [];

for (var k in keys) {
        columns.push({

            'title': keys[k],
            'data': keys[k],
            'targets': k,
            'width': 60
        });

My question now is: How can I achieve similar functionality with JQGrid? I need detailed guidance on working with JSON data in JQGrid compared to my previous experience with datatable.

Answer №1

Upon reviewing the jqgrid documentation, I have successfully implemented the following code:

<table id="list47" ></table>
<div id="plist47"></div>

<script>

    var mydata = JSON.parse('@DATA_QUERIED');


    $(document).ready(function () {

        jQuery("#list47").jqGrid({
            data: mydata,
            datatype: "local",
            height: 'auto',
            rowNum: 30,
            rowList: [10, 20, 30],
            colNames:['USER_ID', 'USER_NAME', 'LOGIN_NAME', 'PASSWORD', 'DESCRIPTION', 'GROUP_ID', 'EMAIL', 'ACTIVE', 'ORGANIZATION_ID'],
            colModel: [
                { name: 'USER_ID', index: 'USER_ID', width: 100, },
                { name: 'USER_NAME', index: 'USER_NAME', width: 140, },
                { name: 'LOGIN_NAME', index: 'LOGIN_NAME', width: 140, },
                { name: 'PASSWORD', index: 'PASSWORD', width: 140, },
                { name: 'DESCRIPTION', index: 'DESCRIPTION', width: 140, },
                { name: 'GROUP_ID', index: 'GROUP_ID', width: 140, },
                { name: 'EMAIL', index: 'EMAIL', width: 200, },
                { name: 'ACTIVE', index: 'ACTIVE', width: 70, sorttype: "int" },
                { name: 'ORGANIZATION_ID', index: 'RGANIZATION_IDz', width: 140, sorttype: "int" }
            ],
            pager: "#plist47",
            viewrecords: true,
            sortname: 'USER_ID',

            grouping: true,
            groupingView: {
                groupField: ['USER_ID'],
                groupColumnShow: [false]
            },
            caption: "This is a sample example of a Grid"
        });

    });
</script>

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

Which domain do I need to use: Google or my own, in order to bypass the Access Denied issue in JQuery

I'm currently experiencing a puzzling issue with my website while using Internet Explorer. Despite loading fine in other browsers, I keep encountering a permission denied error within my JQuery code. What's even more perplexing is that this error ...

Error encountered: Unable to assign onClick property to null object

Hey everyone, I'm running into an issue with my JavaScript. It keeps throwing a TypeError: Cannot set properties of null (setting 'onclick') at SignUp.js:4:43 <HTML> <body> <div class="input-box"> <span class="deta ...

Error encountered while making a REST API call in Ajax: Unforeseen SyntaxError: Colon unexpected

I am currently troubleshooting my code to interact with a REST API. My platform of choice is "EspoCRM" and I aim to utilize its API functionalities. The official documentation recommends using Basic Authentication in this format: "Authorization: Basic " ...

Show all nodes in a single row using jq

Here's my current situation: jq -r '.letters[0].secondary_letters[0] | "\(.name)"' letters.json This command outputs: a aa What I'm aiming for is to have them displayed as: a, aa The structure of the JSON file is like this: ...

Accessing a specific item from a JSON response in Python

I have a specific dataset that I need to extract items from the "item" object. The challenge is that sometimes the response can be an array, and I'm struggling with how to handle this situation in Python. My goal is to iterate through these values and ...

Troubleshooting: AngularJS Form Submission Failure

As a novice in Angular and not a JavaScript expert, I am facing challenges with form submission. My task involves loading movie showtimes from an http API and using ng-repeat to display them within a page container. The REST API requires a zipcode input, w ...

swapping out the image tag for a background image in react-bootstrap

My app was developed using the react-bootstrap framework. Within one of my components, I have an image tab structured like this: render() { return ( <div id="homePage"> <div class="hero"> <Image src="/im ...

Tips for accessing elements inside #shadow-root (open) when clearing browsing data in Chrome Browser with the help of a cssSelector

Recently, I came across a discussion on how to automate shadow DOM elements using Selenium, specifically dealing with #shadow-root (open) elements. During my attempts to locate the Clear data button within the popup for Clear browsing data, which appears ...

Exploring the process of implementing tab-link ripple effects in Angular Material

Is it possible to apply the ripple effect to tabs in Angular elements using a similar attribute to md-ink-ripple, like we can with grid or title elements? For example, check out https://material.angularjs.org/latest/demo/tabs If there isn't a specif ...

Enigmatic void lurking at the pinnacle of a website

My website can be found at: . There seems to be an unusual ~25px gap at the top of the page before the content starts displaying. The current code/layout was inherited from the previous web design company and doesn't meet my standards, but it functio ...

What is the best way to get rid of an underline from a hyperlink

I am facing a peculiar issue where, with each image or word that appears ..... below I have already applied internal and external CSS styles like the following: a:hover { text-decoration: none; } a:link { text-decoration: none; } a:visited { ...

Two floating elements collide as the first one drifts over the second

I am working on a simple webpage that should take up the entire browser window. There are only two elements in it, but the issue is that the second element is being overlapped by the first. form { background-color:#996600; width:30%; height:1 ...

Struggling with formatting images to ensure consistency in size using HTML and CSS

Currently, as a novice in HTML and CSS, I am encountering image misalignment issues while attempting to make them uniform in size. How can this be rectified? The existing HTML code is shown below: <div class="container text-center"> <h3> ...

Enhancing user experience with scroll snapping within nested components/elements

https://i.sstatic.net/PzNmP.gif Looking at the gif, you can see a large scrollable container with various main blocks ('Attack', 'Release', etc.) housed within it. Each main block contains one or multiple columns (such as 'Attack ...

Using JavaScript or JQuery, is there a way to retrieve the favicon icon, Apple-touch icon, and title of a webpage?

Is it possible to extract just the favicon icon and title from a webpage using only an IFrame? For example, for a site like www.stackoverflow.com, I want to retrieve only its title and favicon icon/Apple-touch-icon. Are there any plugins or parsers avail ...

What is the process for incorporating a CSS class into a preexisting Woocommerce/Wordpress widget?

Looking for a way to add additional classes to the Woocommerce Product Categories Widget without tampering with the original source code or creating a replacement widget? The widget_display_callback seems like the way to go, but the available documentation ...

What is the best way to show the logged-in user's name with PHP?

After a successful login, I want to display a personalized greeting message to the user in PHP (e.g. "Hey User!"). However, the code $username = $_SESSION['username']; is not retrieving the username properly and displays nothing (Hey !). Here ...

Fixing the issue with CSS scrollbar swapping

I'm currently working on a template and facing a challenge that I can't quite comprehend. More specifically, I understand why it's happening, but I'm struggling to implement a cross-browser solution. The issue revolves around a fixed b ...

Creating a dynamic dropdown menu using jQuery animation

I am looking to add animation to my top navigation bar. Currently, the dropdown menus just appear suddenly when hovering over the links in the top nav. Development site: I have attempted the following: <script> jQuery(document).ready(function() { ...

I want to save the pincode column from a datatable into a variable and then display it when a button is clicked

var pincode=$(this).closest('tr').children('td.pincode').text(); The code snippet above is functional for non-responsive datatable setups. However, it does not work in the responsive view of the datatable. Is there an alternative solu ...