The functionality of sorting or searching in jqGrid does not support columns that utilize json dot notation

Here is the jqGrid code snippet that I am working with:

$("#report").jqGrid( {
        url:        '/py/db?coll=report',
        datatype:   'json',
        height:     250,
        colNames:   ['ACN', 'Status', 'Amount'],
        colModel:   [ {name:'acn', sortable:true},
                      {name:'meta.status', sortable:true},
                      {name:'amount'} ],
        caption: 'Show Report',
        rownumbers: true,
        gridview: true,
        rowNum: 10,
        rowList: [10,20,30],
        pager: '#report_pager',
        viewrecords: true,
        sortname: 'acn',
        sortorder: "desc",
        altRows: true,
        loadonce: true,
        mtype: "GET",
        rowTotal: 1000,
        jsonReader: {
            root: "rows",
            page: "page",
            total: "total",
            records: "records",
            repeatitems: false,
            id: "acn"
            }
     });

The issue arises from using JSON dot notation in the column 'meta.status' and the corresponding data received from the server:

{"page": "1", "total": "1", "records": "5", "rows": [ 
        {"acn":1,"meta": {"status":"Confirmed"}, "amount": 50},
        {"acn":2,"meta": {"status":"Started"}, "amount": 51},
        {"acn":3,"meta": {"status":"Stopped"}, "amount": 52},
        {"acn":4,"meta": {"status":"Working"}, "amount": 53},
        {"acn":5,"meta": {"status":"Started"}, "amount": 54} ] }

There are two main challenges encountered:

  • Sorting functionality does not operate on columns with dot notation, such as "meta.status". The sortable icons do not appear on the column header, and clicking on the header does not trigger any sorting action, regardless of whether loadonce is set to true or false.
  • If attempting to perform a Search operation (with loadonce set to true) on the column meta.status (other columns without dot notation work fine), it results in a JavaScript error being thrown.

Answer №1

Upon updating the definition of the final column from {name:amount} to {name:'amount'}, I was able to replicate the issue you are experiencing: the sorting on 'Status' is not functioning correctly, although no error message is displayed (refer to the demonstration).

To resolve this issue, one must modify the definition of the second column from

{name:'meta.status', sortable:true}

to

{name:'status', sortable:true, jsonmap: "meta.status"}

View the updated demo here.

Answer №2

To prevent encountering this issue, keep the following guidelines in mind:

  1. Make sure that your name and index values match

    name: 'Date', index: 'Date',
    name: 'Clicks', index: 'Clicks',
    ...
    
  2. Ensure you specify something like

    $("#jqGrid").setGridParam({datatype: 'local'}); 
    

    When reloading the grid, make sure to switch back to "JSON" if that's what you're using - for example:

    $("#yourGridID").setGridParam({datatype: 'json'}).trigger("reloadGrid");
    
  3. Lastly, remember to include

    name: 'Date', index: 'Date', sortable:true
    

    Wherever it is required.

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

conceal or reveal a button based on the authentication status of a user in a

I'd like to display a "Become Tutor" button if either: 1. The user is not logged in. 2. The logged-in user is not already a tutor. Otherwise, I want to show the "Tutor Dashboard" button for users who are already tutors. While my code is functional, i ...

How do I use props to enable and conceal elements like lists, buttons, and images?

Check out this unique component: <ReusedHeader H1headerGray="text here... " H2headerRed="text2 here ! " pheader="p1" getStarted="button text1" hrefab="button url 1" whatWeDo="button text ...

Encountering a node js issue: "Error: Unable to modify headers after they have been sent."

Encountering an error in node.js, specifically during login or when the code crashes. The error message reads: “Error: Can't set headers after they are sent.” err: Error: Can't set headers after they are sent. at validateHeader (_http ...

Using Redux to add an object to an array nested within another array

Hey there! I'm facing an issue with creating, updating, or deleting {note} in the [notes] array based on the operationId in the parent array id. I've tried using ADDNOTE but it's not working as expected. The problem is that without these fun ...

Angular 5, utilizing rxjs to map to JSON, encountered an issue where 'json' is not recognized on the type 'object'

Having trouble following an online video tutorial on Angular, none of the other solutions seem to be working for me. https://i.sstatic.net/KMNT4.png import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/co ...

What is the best way to ensure that the page reloads every time I access it

Creating a social networking website and working on a post edit page. However, encountering an issue when finishing editing the post and clicking 'SAVE EDIT'. I am using the code window.location='post_info.php?post_id='+postid; with AJA ...

What is the method to utilize Selenium with Python for extracting JavaScript elements?

I'm having trouble parsing the "disabled" attribute using Beautiful Soup. Is there a way to achieve this with Selenium in Python? The specific website I am trying to parse is: Size ...

Exploring custom JavaScript with Construct 2's generated code

How can I access the score of a game user in Construct2 Engine using external JavaScript? Is there a method to achieve this? Appreciate any guidance on this matter. ...

Tips for displaying diverse content in a DIV container when users click on various sections of an image

Apologies for the unclear title, but I'm struggling to explain my technical goal using jargon. The basic concept is this: there will be an image on the webpage, and when a user clicks on a specific area of the image, relevant information will appear ...

Building Individual Elements in Angular 2

My task involves creating two distinct components in Angular 2, the Users component and the Clients component. These components are not nested and do not have any relationship. To call these components separately, I typically use main.ts as the main entry ...

Python application for tracking shipments through FEDEX API

I've been diving into building a Python program utilizing the FedEx tracking API. I believe I have the correct code in place and have successfully registered with FedEx to obtain the necessary API keys. However, I'm struggling to identify which p ...

The interactivity of data-ng-click in HTML is not functioning as expected

I need help with implementing the data-ng-click functionality for a dynamically created button. Can someone assist me with this? var table = document.getElementById("dashboard"); for( var i = 0; i < $scope.namesOfMembers.length; i++ ){ var row = t ...

The leave animation for Angular's ngAnimate and ng-view feature appears to be malfunctioning

angular version: 1.6.1 I am attempting to create a fade in/out effect for my ng-view element, however, I am encountering an issue where only the enter animation is functioning properly. This is the relevant HTML code: <main class="main" ng-view>&l ...

Incorporating graphics into a React component

Currently exploring React JS and looking to dive into the practical side of things. Following a documentation tutorial that constructs a basic comment system. I've replicated the component structure outlined in the tutorial: PostBox PostList Pos ...

What is the most efficient way to use multiprocessing to insert a large number of documents (100 million) into a local MongoDB

I have been able to successfully insert selected keys from multiple JSON files into a local MongoDB database. However, as the collection grows beyond 100 million rows, the insertion process becomes extremely slow. I believe utilizing multiprocessing coul ...

Issues with tabs functionality in Bootstrap version 4.3.1, unlike the smooth operation in v4.1.0

I encountered an interesting situation recently. After spending almost 3 hours troubleshooting my code, I discovered that it functions perfectly on Bootstrap v4.1.0 but fails on the latest version, v4.3.1. Working JSFiddle with Bootstrap v4.1.0: https://j ...

Explore the wonders of our solar system using three.js!

I am embarking on my first project using three.js to create a miniature solar system consisting of 1 star, 2 planets, and 1 moon orbiting each planet. As a beginner to both three.js and JavaScript in general, I am eager to learn. Currently, I have success ...

Transferring data from the View to the Controller is not functioning as expected

I am attempting to pass a variable from my view to a controller in order to utilize it in another view. Despite referencing some examples on how to achieve this, I have not been successful. Below is my model: public class GameResultsViewModel { publi ...

Getting YQL financial information using jQuery and showing it using the .html() method

Struggling with the .html() function and YQL data pulled issue. Despite data being pulled successfully (as seen in the YQL console), it is not being displayed. Here's the provided code snippet: HTML Section <ul id="TECO-container"> <li ...

What is the process of utilizing a different <Consumer> within a <Provider>?

./App.js import React from "react"; import ReactDOM from "react-dom"; import { Provider } from './context.js'; import { Provider as Provider2 } from './context2.js'; import Child from './Child.js'; import "./styles.css"; cl ...