Having difficulty refreshing the JGrid with updated content

I am currently utilizing JQuery and JGrid in conjunction with Java. I have a grid set up

     <script>
     jQuery("#table1").jqGrid({
     .............. 
     ............ 
     });

Additionally, I have another grid

      function abc {
      var id = firstgridid;
      if(number>0) {
      // It is working fine but using the previous value
      $("#table2").jqGrid('setGridParam', { url: 'JGridA?action=abc&hidden='+id,page:1}).trigger("reloadGrid");

      JQuery("#table2").jqGrid({
      url:'JGridServlet?action=comm&hidden='+id,
      .............
      });
      }
      </script>

Within the second grid, I am passing the selected id value from the first grid as part of the URL. Whenever I choose a row from the first grid and then click on the "show details" button, the function abc() will be executed. The id should be passed along for display of corresponding rows (with id information) in the second grid.

Though I can access the id of the selected row and trigger a reload of the second grid successfully, the query pertaining to the second grid is still using the initially selected id. However, my requirement is to use the presently selected id.

Your assistance would be greatly appreciated.......

Answer №1

In the code of the abc function, there are at least two significant issues that can be identified.

The first problem arises from the improper usage of setGridParam before initializing the grid with JQuery("#table2").jqGrid({...});. This sequence results in an attempt to apply setGridParam on the empty <table>, which is not valid. The correct approach is to first create the grid (convert the empty <table> into a functional grid) and then proceed to use setGridParam or .trigger("reloadGrid") for updating the grid content.

The second issue stems from calling JQuery("#table2").jqGrid({...}); multiple times within the abc function. As mentioned earlier, this call converts the empty <table> into a grid. Hence, it should only be made once. Subsequent updates to the grid should be handled by using setGridParam and .trigger("reloadGrid") instead.

UPDATED: For implementing a master/details scenario, you can follow these steps:

// create master grid
$("#table1").jqGrid({
    datatype: "json",
    url: "masterGridUrl",
    onSelectRow: function (rowid, state) {
        if (state) { // if not the same row was previously selected
            // refresh detail grid
            $("#table2").jqGrid("setGridParam", { datatype: "json"})
                .trigger("reloadGrid", [{page: 1}]);
        }
    },
    ... // other options
});

// create details grid without filling the data initially
$("#table2").jqGrid({
    datatype: "json", // we use "local" instead of "json" to have to request to the server
    url: "JGridA",
    postData: {
        action: "abc",
        hidden: function () {
            
            return $("#table1").jqGrid("getGridParam", "selrow");
        }
    },
    ... // other options
});

This setup creates a master grid "#table1" and an empty detail grid "#table2". When a row is selected in the master grid, the detail grid will be reloaded. Additional parameters sent to the server include a static parameter action=abc and the value of the rowid from the master grid.

If navGrid is used in the master grid, a beforeRefresh callback can be added to clear the data in the detail grid. This ensures that the detail grid remains empty until a row is selected in the master grid.

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

Issue with undefined bindingContext.$data in IE9 on knockout binding handler

I'm attempting to create a unique binding handler that applies role-based access to fields on a page. This custom handler uses the values of other observables from the viewModel to enable or disable input controls based on certain conditions. However ...

An effective way to prevent right-clicking on iframes across all websites

I am facing an issue with disabling right click for the iframe. I've successfully disabled it for the default URL of the IFrame, but when displaying any other webpage, the right click remains usable. Below are the sample codes I have used: document.o ...

Exception: The method or property 'activePackage' does not exist in the given context

When setting the Fieldname in the iReport to match the attribute name in the entity class, an Exception is encountered. java.lang.NoSuchMethodException: Unknown property 'activePackage' at org.apache.commons.beanutils.PropertyUtilsBean.getSi ...

The issue I'm facing is that the Bootstrap 4 modal is not visible when I

In my component, I am iterating through data and passing it to another component as props repeatedly. The bootstrap modal is working smoothly with no errors at all. Take a look at my code snippet: render() { const { datas, amt, dis_price, type_dis_price ...

Creating an Angular form that adapts to changing input values

I'm encountering a problem with angular not recognizing the dynamic values from my inputs. My objective is to have angular populate hidden form fields with lat/lon when a user clicks on the map. The user then submits the form, but the data ends up mi ...

How to automatically close a Bootstrap modal after submitting a form

I am facing an issue with a Bootstrap modal dialog that contains a form. The problem is that when I click the submit button, the form is successfully submitted but the modal dialog does not close. Here is the HTML code: <div class="modal fade" ...

Identify and emphasize fields that contain identical, non-empty values

I am attempting to compare the values of textboxes and highlight them if they are the same, excluding any textboxes that are empty. Feel free to view an example on this JSFiddle link: http://jsfiddle.net/qjqa1et2/61/ Below is the jQuery code I am current ...

"Exploring the possibilities of Ajax in conjunction with Sol

I recently completed a tutorial on Ajax Solr and followed the instructions in step one. Below is the code I wrote: header.php: <script type="text/javascript" src="static/js/ajax-solr/core/Core.js"></script> <script type="text/javascript" s ...

Guide to integrating promises into the HTML5 Geolocation API

How can I fix the code below to ensure that the getPreciseLocation function does not return an undefined value? In essence, when the user clicks on the #precise-location-prompt and shares their location with the browser, there should be an AJAX call to re ...

Tips for assigning a Custom Formik Component's value to the Formik value

I'm currently integrating Formik into my form alongside Google Places auto-complete feature. My goal is to display the places auto-complete functionality as a custom component within the Formik field. form.js <Formik initialValues={location:" ...

What is the reason behind taps in TypeScript only registering the first tap event?

One issue I am encountering is that only the first tap works when clicked, and subsequent taps result in an error message: Uncaught TypeError: Cannot read properties of undefined (reading 'classList') Here is the code I am using: https://codepen ...

Using the datepicker class in an input field causes issues with the functionality of the bootstrap datepicker, specifically the autoclose, endDate, and startDate properties do not function as

I'm facing an issue with my code when I add the datepicker to the input field's class. JS $(document).ready(function () { $("#ActionDateInput").datepicker({ autoclose: true, endDate: new Date() }); }); HTML <input type= ...

Investigating Jquery Flip Card Issues

Looking to create a set of flip cards using HTML, CSS, and jQuery. Currently facing an issue where only the first card is flipping when clicked. Any suggestions on how to modify the jQuery code to make it work for all cards would be highly appreciated. C ...

The value of This.state is found to be zero while being used inside the

I am attempting to convert all selected item IDs from a Redux store into the item names and then save them into the state. The issue I am facing is that the spread operator within the setState function results in zero. Do I need to bind the context of the ...

An Illustrative Example of Inheritance in Javascript?

I've been searching on various platforms for a straightforward example of inheritance without much luck. The examples I've come across are either too complex, obscure, or just not user-friendly. I have multiple service functions that all share so ...

Attempting to successfully integrate the Prerender SPA Plugin with Vue.js CLI 3

Encountering an issue while attempting to build: Building for production...Error: ENOENT: no such file or directory, stat '/Users/me/Code/project/index.html' Software Package: "prerender-spa-plugin": "^3.1.0" Location: vue.config.js: const Pr ...

What's the issue with reducers receiving a Function instead of an Object in Redux?

I encountered an error in my react and redux project but I am unable to figure out how to fix it. Here is the error message: The reducer received unexpected type "Function" as the previous state. It was expecting an object with keys: "posts", "sidebar" ...

Java code for Quicksort with Random Pivot not producing expected results

I am currently working on a quicksort algorithm with a random pivot, but I am facing an issue where the random array is not being sorted completely. I suspect that the problem lies within the bounds of the recursive calls and the swapping process. pub ...

updating a div with URL redirection instead of global redirect

I am facing an issue with redirecting my website flow to the login page when a user clicks any link on the page after the session has expired (either due to timeout or manual logout from another window). In an attempt to solve this, I inserted the followi ...

Preventing Duplicate Entries in Angular Data Posting

I am currently trying to submit a form to a PHP page that will then return a table of data. The process works perfectly fine if I do not include any parameters in the post request. However, as soon as I try to add parameters for the query, I encounter an n ...