在Struts2中作为表单的一部分提交时,如何在jquery网格中捕获选定的行 [英] How to capture the selected rows in jquery grid when submitting as part of the form in Struts2

查看:78
本文介绍了在Struts2中作为表单的一部分提交时,如何在jquery网格中捕获选定的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery网格和Struts2.我已经成功显示了jQuery网格.现在,我想从jquery网格以及网格外部的其他数据中选择行,并将其提交到我的struts操作中进行处理.我从jquery网格检索数据时遇到问题.谁能帮助我访问在动作中从jquery网格中选择的行?

I am using jquery grid and Struts2. I have displayed the jquery grid successfully. Now i want to select rows from jquery grid plus other data outside grid and submit that in my struts action for processing. I have a problem with retrieving the data from jquery grid. can anyone help on how to access the rows that i have selected from jquery grid in my action?

这是我的jquery网格:

here is my jquery grid:

<s:form action="runTest" method="post">
                <sjg:grid
                    id="gridTable"
                    formIds="mcp"
                    caption="Test Scripts"
                    dataType="json"
                    href="%{searchurl}"
                    pager="true"
                    gridModel="gridTDP"
                    rowList="10,15,20,30"
                    rowNum="30"
                    multiselect="true"
                    viewrecords="true"
                    reloadTopics="reloadItems"
                    loadonce="false"
                    viewsortcols="[true, 'horizontal', true]"
                    resizable="true"
                >

                    <sjg:gridColumn name="idTestData"
                        index="idTestData"
                        key="true"
                        title="idTestData"
                        formatter="integer"
                        hidden="true"
                    />

                    <sjg:gridColumn name="testName"
                        index="testName"
                        title="Test Name"
                        width="50"
                        sortable="true"
                        search="true"
                        searchoptions="{sopt:['eq','ne','lt','gt']}"
                    />
                    <sjg:gridColumn
                        name="projectName"
                        index="projectName"
                        title="Project Name"
                        width="300"
                        sortable="true"
                        edittype="text"
                    />

                </sjg:grid>

                <sj:submit value="Execute Test Scripts"/>
            </s:form>

这是已成功调用但未获取jquery网格行的runTest.action:

Here is the runTest.action which is successfully called on but not getting the jquery grid rows:

public String runTest() throws Exception{

        Iterator<Test> gridIterator = gridTDP.iterator();

        System.out.println(" running test--");
        while(gridIterator.hasNext()){

            System.out.println(" in the gridIterator");
        }

        return "success";
    }

推荐答案

如果我是对的,我认为这可能有效.

If I am correct I think this might work.. If not let me know.

var checks=$("#gridtable").find('input[type=checkbox]');
               var va =new Array();
              // alert(checks.length);
                for(var i=0;i<checks.length;i++)
                    {
                        if(checks[i].checked)
                            {
                             var p = checks[i].parentNode.parentNode;
                             var id=p.id;

                            va.push($("#gridtable").jqGrid('getCell',id,'cellvalue'));
                //          alert(va);
                            }
                    }
               document.getElementById("hiddenVariableID").value=va; 

cellvalue是要发送给操作类的值. 我认为在您的情况下,它可以是任何列名称.

that cellvalueis the value that you want to send to the action class. I think in your case it can be any column name.

在您的jsp中添加该行

in your jsp add thi line

<s:hidden id="hiddenVariableID" name="selectedRows" />

然后在您的动作类中为selectedRows创建Getterssetters,类型为array

And in your action class create Getters and setters for selectedRows with the type as array

这篇关于在Struts2中作为表单的一部分提交时,如何在jquery网格中捕获选定的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆