The jqGrid colModel is failing to execute a function as expected

Within the given code snippet, the function attrSetting is invoked. However, when I modify it to

{"name":"A", "index":"0", "cellattr":attrSetting}
, the code executes smoothly. But here lies the issue - cellattr interprets it as a string rather than a function.

let gridData = {"list":[{"A":"abc", "B":"def", "C":"IRIS", "D":"Testing","E":"17-12-2012","F":"Test", "attr":{"A":{"rowspan": 3}}},{"A":"abc", "B":"def", "C":"IRIS", "D":"Testing","E":"17-12-2012","F":"Test", "attr":{"A":{"display":"none"}}},{"A":"abc", "B":"def", "C":"IRIS", "D":"Testing","E":"17-12-2012","F":"Test", "attr":{"A":{"display":"none"}}}]};
$(document).ready(function(){
prepareGrid();
});
function prepareGrid(colModel) {
$("#grid").jqGrid({
    datatype    :   'local',
    contentType :   'application/json',
    data        :   gridData.list,
    loadtext    :   "Loading...",
    colNames    :   ['TB Element','GL Element', 'Company Name', 'Status', 'Date', 'User'],
    colModel    :   [
                     {"name":"A", "index":"0", "cellattr":"attrSetting" },
                     {name:"B", index:1 },
                     {name:"C", index:2},
                     {name:"D", index:3},
                     {name:"E", index:4},
                     {name:"F", index:5}
                    ],
    width       :   '500px',
    height      :   '200px',
    rownumWidth :   30,
    scrollrows  :   true,
    shrinkToFit :   false,
    rownumbers  :   true,
    viewrecords :   true,
});
};
function attrSetting(rowId, val, rawObject, cm) {
   let attr = rawObject.attr[cm.name], result;
   if (attr.rowspan) {
      result = ' rowspan=' + '"' + attr.rowspan + '"';
   } else if (attr.display) {
      result = ' style="display:' + attr.display + '"';
   }
   return result;
};

Answer №1

If you consider making a modification,

"cellattr": attrSetting

is the way to go.

Furthermore, it's crucial to be cautious when utilizing jqGrid options. Your current code is riddled with various issues. Here are just a few examples:

  • If you opt for datatype: "local", make sure to eliminate any index properties from your colModel or ensure they match the values in the name property precisely. Failure to adhere to this rule will render the columns unsortable and impede the searching/filtering of local data.
  • You have not utilized the pager or toppager options of jqGrid. I highly recommend specifying the rowNum option with a sufficiently large value such as rowNum: 10000. The default rowNum value is 20 (refer to the "Default" column in the table outlining the available options). Thus, jqGrid will only display the initial 20 rows from the provided array gridData.list.
  • The values for width and height must be numerical figures like 500 or 200, rather than strings like '500px' and '200px'. You can use the string "auto" or "%100" for the height value.
  • An essential option missing from your code is contentType.
  • I suggest enabling the gridview: true and autoencode: true options.

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

resolve CORs issue with api in express app.get( ' /* ')

Can you please explain how to retrieve data from a JSON API? server.js app.get('/*', function(req, res) { res.sendFile(path.join(__dirname, 'public', 'index.html')); }) app.get('/api', function(req, res) { ...

Is it possible to alter the name of a slot before displaying the element in the shadowDOM, depending on the slot utilized in the DOM?

In my project, I am working on implementing different features for both desktop and mobile devices. Some of these features can be replaced by slots. My goal is to have a slot that can be either replaced by a desktop slot called poster-foreground, or a mobi ...

Embracing PWAs with subdomains – seamless installation

One of my Progressive Web Applications (PWA) called app A contains a link to another app, app B. Initially, I hosted both apps on the same subdomain (for example: ) and everything worked perfectly - installing app A also installed app B. However, when I a ...

What is the clarification on AngularJs' ng-options?

In my demo, I have a small setup. Essentially, it consists of a select element with the following data: address: { select: { code: "0", name: "Select proof of address" }, letter: { ...

The issue with Nuxt's vue-Router page transitions not functioning properly is due to the presence of a request

Encountering an issue with the combination of nuxt/vue-router page-transitions and the JavaScript method rerequestAnimationFrame. Currently, I am animating a container of items using rerequestAnimationFrame along with the transform: translate CSS property. ...

Why is the Google Map missing from the Bootstrap modal dialog?

I have multiple links on my website, each describing a different location with unique map data. I would like to display a modal bootstrap dialog with an embedded Google map when a user clicks on any of the links - ensuring that the location shown correspon ...

Java code to extract and delete a section of a website on a webpage

@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ View view = inflater.inflate(R.layout.fwebview, container, false); webView = (WebView) view.findViewById(R.id.webView); String url = ge ...

Utilize JavaScript to extract and exhibit various SQL records stored within a multidimensional array

How can I use JS, JQuery, PHP, and MySQLi to automatically generate an HTML table within a div on a webpage? The table should display data based on user-input search criteria. For example, the user enters a start date and end date, clicks a button, which t ...

Alternatives to the PHP Foreach Tree Approach

I often find myself using nested foreach loops when parsing JSON data in my workflows, but I can't shake the feeling that there must be a more efficient solution out there. I've come across mentions of array_walk as a possible alternative, but I& ...

Implementing conditional dropdown menus with CodeIgniter

Explore the District Master Table: Dive into the District table: District Master District I need assistance with a form page that includes a Category dropdown. The district table stores district codes and category names. I want to display district names ...

How exactly does this JavaScript code determine the index of the maximum value within an array?

Examining the specific line of code: let largest = arr.reduce((a,v,i) => v > a[1] ? [i,v] : a, [-1,0]); I find this part a, [-1,0] particularly perplexing, as I am unsure of its syntax. How does a function before the comma? ...

Using Jquery to generate key value pairs from a form that is submitted dynamically

I'm still learning the ropes of jquery and struggling with a specific issue. I'm looking for a way to dynamically set key:value pairs in the code below based on form inputs that have variable values. The code works when I manually add the key:va ...

Ways to determine if an element is at the top of a page

I need help with a test case that involves checking if the title scrolls up to the top of the page when a button is clicked. The challenge is that there is a default header on the page, so the title should scroll below that. How can we verify this scenar ...

The JavaScript button's onClick event is not functioning properly, despite the method executing normally

I'm currently working on creating a button using JavaScript that, when clicked, will trigger an AJAX request to some PHP code. Interestingly, I have already set up three buttons with the same functionality and they are all functioning perfectly. Wha ...

Issue with useEffect EventListener in REACT HOOKS

Recently, I attempted to create a simple Snake-Game using REACT. Everything was going smoothly until I encountered an issue with using useEffect for moving the "snake" when a keydown event is triggered. The challenge arose when trying to implement moveSnak ...

Decoding an oddly structured JSON object using Json.NET

Trying to convert this oddly-shaped JSON object into a more logical class structure. { "item": { "article_title": { "type": "text", "value": "Title of article 1" }, "content": { "type": "text ...

Adding a new element with Jquery when a dropdown option is selected

What is causing this issue to not function properly? <script> $(document).ready(function(){ $('#custom_field option').click(function(){ $('#custom_field_input').append('<tr><td></td> ...

Tips for fetching data from a database using AJAX when the values of two drop-down lists are involved

I have successfully implemented an Example where I retrieve data using a single drop-down list from a database. Now, I want to extend this functionality to work with two drop-down lists, where the values retrieved from the database are dependent on the sel ...

Simplify intricate JSON data into basic POJO files effortlessly for Android applications

Looking for a way to streamline the conversion of complex JSON responses into simple POJO objects. While tools like www.jsonschema2pojo.org can do the job, they generate too many files - 47 in my case. I'm seeking a solution that will give me just a h ...

The delete function is not functioning

I need help with implementing a custom Angular directive that includes a delete button to remove itself. When I click the button removeMe, it is not deleting an item from the array. Any suggestions on what might be causing this issue? HTML: <button t ...