1

I have two struts2 jQuery grids in my page. I have to load the 2nd grid on row click of the first grid. I have added a rowselect event listener to the first grid and in that method I am trying to reload the grid.

$("#dgJobsDetailMain").jqGrid().trigger("reloadGrid");

I also tried firing an Ajax request

function populateJobRunDetails(jobName,dbSid)
{
    $.ajax({
        url: "ecmComparisonJobDetailDataAction?jobId="+jobName+"&selectedDbSid="+selectedDbSid+"&date="+new Date().getTime()+"&rowClicked=true",
        type: "GET",
        dataType: "json",
        success: function(data,textStatus,jqXHR)
        {
            //$("#dgJobsDetailMain").jqGrid().trigger("reloadGrid");
        },
        error:function(jqXHR, textStatus, errorThrown)
        {
            alert('error');
        }   
      }); 
}

My problem is

  1. Action's execute method gets several times for every action. When I ran the application on debug mode, i found that the action classes execute method got called three times. of which, the selected values from the jsp pages were bound to the action classes variable twice and the third time, the values were null.
  2. And when I fire the reload grid event on success of the ajax function, the action class params are set to null, so I am unable to proceed with the data fetch.

1st grid

<sjg:grid viewrecords="true" formIds="ecmComparisonMainForm" reloadTopics="reloadDataGrid" pagerPosition="center" onSelectRowTopics="rowselect" id="dgJobsMain" caption="Job List" dataType="json"  href="%{ecmComparisonDataActionUrl}" pager="true"  
            gridModel="gridModel"  rowList="4,6,8" rowNum="5"  rownumbers="true" height="150" width="1200">        
             <sjg:gridColumn name="jobId" index="jobId"  title="Job ID" hidden="true" />
             <sjg:gridColumn name="jobName" index="jobName"  title="Job" sortable="true" />
             <sjg:gridColumn name="jobDescription" index="jobDescription" title="Job Description"  sortable="true"/> 
             <sjg:gridColumn name="database" index="database" title="Database" sortable="false" /> 
             <sjg:gridColumn name="sourceSchema" index="sourceSchema" title="Source Schema" sortable="false"/> 
             <sjg:gridColumn name="targetSchema" index="targetSchema" title="Target Schema" sortable="true"/>
             <sjg:gridColumn name="prDescription" index="prDescription" title="PR Description" hidden="true" sortable="false"/>
             <sjg:gridColumn name="createdDate" index="createdDate" title="Created Date" sortable="false"/>
             <sjg:gridColumn name="createdBy" index="createdBy" title="Created By" sortable="false"/>
</sjg:grid>

Row select function

$.subscribe('rowselect', function(event, data) 
{
    rowClicked = true;
    var grid = event.originalEvent.grid; 
    var sel_id = grid.jqGrid('getGridParam', 'selrow'); 
    var jobName = grid.jqGrid('getCell', sel_id, 'jobName');

    var dbSid = document.getElementById('schemaDbSid');
    $("#dgJobsDetailMain").jqGrid().trigger("reloadGrid");
    //populateJobRunDetails(jobName,dbSid.value);
}
);

2nd Grid

<sjg:grid pagerPosition="center" id="dgJobsDetailMain" caption="Job Details List" dataType="json"  href="%{ecmJobRunDetailsActionUrl}" pager="true"  
            gridModel="jobsDetailGridModel"  rowList="4,6,8" rowNum="5"  rownumbers="true" height="150" width="1200">        
             <sjg:gridColumn name="runId" index="runId"  title="Run" sortable="true" />
             <sjg:gridColumn name="startDate" index="startDate" title="Start Time"  sortable="true"/> 
             <sjg:gridColumn name="endDate" index="endDate" title="End Time" sortable="false" /> 
             <sjg:gridColumn name="status" index="status" title="Run Status" sortable="false"/> 
             <sjg:gridColumn name="statusMsg" index="statusMsg" title="Status Details" sortable="true"/>
</sjg:grid>

Action class:

//Form variables/getter setters

public String execute()
{
// code to database
}

public String getJSON()
{
return execute();
}

Please let me know what is missing.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Karthick R
  • 599
  • 9
  • 25

4 Answers4

0

After reading your code , I guess you should reload the grid like this.

var grid = jQuery("#yourGridId");
grid.trigger("reloadGrid");
arvin_codeHunk
  • 2,328
  • 8
  • 32
  • 47
0

Add the attribute reloadTopics to your Grid and publish this if you need it. This has some benefits again plain trigger reloadGrid. At example the formIds attribute fas also respected.

<sjg:grid id="myGrid" reloadTopics="reloadMyGridTopic" ... />

<script>
$.publish("reloadMyGridTopic");
</script>
Johannes
  • 2,060
  • 3
  • 17
  • 27
0
$("#dgJobsDetailMain").jqGrid('setGridParam',{url:'/context/action_name?param1='+value1+"&param2="+value2}).trigger("reloadGrid");

This solved my issue. Strange, since I tried the same thing with s:url and s:param. It din't work.

-Karthick

Karthick R
  • 599
  • 9
  • 25
0

Try this:

      $.ajax({
            url: "myAction.action", cache: false, dataType: 'json', data: "Id=" +
                    Id,
            success: function (data) {
                var jsonData = JSON.stringify(data.jsonResponse);
                var parsedData = JSON.parse(jsonData);
                if (parsedData.hasResults) {
                    var myData = parsedData.jsonResults;
                    $(document).ready(function () {
                        var allParameters = $("#gridModel").jqGrid("getGridParam");
                        allParameters.data = myData;
                        $("#gridModel").trigger('reloadGrid');

                    });
                }
            } });

In ur action class, set the grid list to json response:

jsonResponse = JsonResponses.collectionResponse(list);

madhu pathy
  • 429
  • 2
  • 6