gigaZhang / struts2-jquery

Automatically exported from code.google.com/p/struts2-jquery
0 stars 0 forks source link

dynamic data reload to grid on form submit #801

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

I have a grid which load data on page load.
I also have a form that on submit calls an action correctly, but it doesnt load 
new data on my grid.

This is my code:

<s:url id="getCurrentDateLogs" action="getCurrentDateLogs"/>

<sjg:grid
    id="getLogs"
    dataType="json"
    href="%{getCurrentDateLogs}"
    gridModel="listOfLogs"
    onSelectRowTopics="rowselect"
    loadonce="true"  
    >
    <sjg:gridColumn name="userid" index="userid" title="User ID" sortable="true" align="center"/>
    <sjg:gridColumn name="username" index="username" title="Username" sortable="true"/>
    <sjg:gridColumn name="logaction" index="logaction" width="600" title="Action" sortable="true"/>
    <sjg:gridColumn name="date" index="date" title="Date" sortable="true" sorttype="date" align="center"/>
    <sjg:gridColumn name="time" index="time" title="Time" sortable="true" sorttype="time" align="center"/>     
</sjg:grid>

<s:form action="getLogsByDates" id="form2"  theme="simple" cssClass="yform">
    <table class="">
        <tr><td>from:</td>
            <td><sj:datepicker value="yesterday" id="from" name="startDate" displayFormat="dd/mm/yy" label="from" /></td>
        </tr>
        <tr><td>to:</td> 
            <td><sj:datepicker value="today" id="to" name="endDate" displayFormat="dd/mm/yy" label="to" /></td>
        </tr>
        <tr><td colspan="2">
        <sj:submit
            value="Search" 
            button="true"
            indicator="indicator"
            />
        </td></tr>
    </table>
</s:form>

What is the expected output? What do you see instead?
Load different data from form action to grid. 
I see instead of that a correct json result from action on screen.
({"JSON":"SUCCESS","endDate":"28\/03\/2012","listOfLogs":[{"date":"27-03-2012"..
. etc.)

Which struts2 version?
struts2 2.3.1.2

Which struts2-jquery plugin version?
struts2-jquery 3.3.0
struts2-jquery-grid-plugin 3.3.0

Original issue reported on code.google.com by tererog...@gmail.com on 28 Mar 2012 at 4:35

GoogleCodeExporter commented 9 years ago
You can do this with reloadTopics and formIds attribute:

<s:url id="getCurrentDateLogs" action="getCurrentDateLogs"/>

<sjg:grid
        id="getLogs"
        dataType="json"
        href="%{getCurrentDateLogs}"
        gridModel="listOfLogs"
        onSelectRowTopics="rowselect"
        loadonce="true"
        reloadTopics="reloadGrid"
        formIds="form2"
    >
    <sjg:gridColumn name="userid" index="userid" title="User ID" sortable="true" align="center"/>
    <sjg:gridColumn name="username" index="username" title="Username" sortable="true"/>
    <sjg:gridColumn name="logaction" index="logaction" width="600" title="Action" sortable="true"/>
    <sjg:gridColumn name="date" index="date" title="Date" sortable="true" sorttype="date" align="center"/>
    <sjg:gridColumn name="time" index="time" title="Time" sortable="true" sorttype="time" align="center"/>
</sjg:grid>

<s:form action="getLogsByDates" id="form2"  theme="simple" cssClass="yform">
    <table class="">
        <tr><td>from:</td>
            <td><sj:datepicker value="yesterday" id="from" name="startDate" displayFormat="dd/mm/yy" label="from" /></td>
        </tr>
        <tr><td>to:</td>
            <td><sj:datepicker value="today" id="to" name="endDate" displayFormat="dd/mm/yy" label="to" /></td>
        </tr>
        <tr><td colspan="2">
        <sj:submit
            value="Search"
            button="true"
                onClickTopics="reloadGrid"
            indicator="indicator"
            />
        </td></tr>
    </table>
</s:form>

Original comment by johgep on 27 Apr 2012 at 5:03

GoogleCodeExporter commented 9 years ago
Hello please i have tested this but it does not work can you give an exemple 
please

Original comment by laabid...@gmail.com on 15 May 2012 at 2:23

GoogleCodeExporter commented 9 years ago
Hi,

I have the same problem and have tried the above approach. In Chrome, server 
returns full json object in text format, while in Firefox, it hangs. Not sure 
what could be wrong.

I am using Struts2-core-2.1.8.jar and jquery and jgrid plugin 3.3.1.

Please advise.

Thanks!

Original comment by ramcdwiv...@gmail.com on 2 Jul 2012 at 1:08

GoogleCodeExporter commented 9 years ago
I feel more popular use case could be - 

We have a default results in Grid, while have a search form above GRID. When 
search form is submitted, reload the GRID with updated results.

I tried doing it but could not releod the Grid, I have explained my issue in 
detail here 
http://stackoverflow.com/questions/14466984/struts2-jquery-grid-ajax-data-reload
-on-form-submit

Original comment by ghotanka...@gmail.com on 22 Jan 2013 at 9:05

GoogleCodeExporter commented 9 years ago
i have followed suggestion by johgep and it is working. However, it is 
refreshing the whole page and when that happens it doesn't stay in that page 
but redirect to the homepage. Is there an attribute that i need to set so it 
stays in the same page?

thanks a lot for your help.

Original comment by alali...@gmail.com on 4 Jan 2014 at 2:36