Struts 2 jQuery网格从JSON字符串加载数据 [英] Struts 2 jQuery grid load data from JSON string

查看:87
本文介绍了Struts 2 jQuery网格从JSON字符串加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我们可以使用JSON字符串加载jqGird。
请参阅将JSON数据映射到jqGrid

I found that we can load the jqGird with JSON string. Please refer to map JSON data to jqGrid

是否可以将此功能与 sjg:grid 标记一起使用。

Is it possible to use this feature with sjg:grid tag.

我查看tag属性,发现数据可以从一个URL加载,该URL将调用一个struts动作,该动作返回一个JSON数据,但在我的程序中我已经有了JSON值,需要将它传递给jqGird。

I look at tag attribute and only find that the data can be loaded from a URL which will call a struts action and that action returns a JSON data, but in my program I already have the JSON value and need to pass it to jqGird.

如果标签不支持数据,那么使用struts中包含的jqGrid的最佳方法是什么2 jQuery插件。

If the tag does not support data, what is the best way to use jqGrid which are included in Struts 2 jQuery plugin.

推荐答案

dataType =local设置为 sjg:grid 并删除 href 属性。然后从数组中提供行数据。例如

Set the dataType="local" to the sjg:grid and remove href attribute. Then provide row data from the array. For example

<sjg:grid
    id="gridtable"
    caption="Example (Editable/Multiselect)"
    dataType="local"
    pager="true"
    navigator="true"
    navigatorSearchOptions="{sopt:['eq','ne','lt','gt']}"
    navigatorAddOptions="{height:280, width:500, reloadAfterSubmit:true}"
    navigatorEditOptions="{height:280, width:500, reloadAfterSubmit:false}"
    navigatorEdit="true"
    navigatorView="true"
    navigatorViewOptions="{height:280, width:500}"
    navigatorDelete="true"
    navigatorDeleteOptions="{height:280, width:500,reloadAfterSubmit:true}"
    gridModel="gridModel"
    rowList="5,10,15"
    rowNum="5"
    rownumbers="true"
    editurl="%{editurl}"
    editinline="true"
    multiselect="true"
    onSelectRowTopics="rowselect"
    >

    <sjg:gridColumn name="id" index="id" title="Id" formatter="integer" editable="false" sortable="true" search="true" sorttype="integer" searchoptions="{sopt:['eq','ne','lt','gt']}"/>
    <sjg:gridColumn name="name" index="name" key="true" title="Country Name" editable="true" edittype="text" sortable="true" search="true" sorttype="text"/>

</sjg:grid>
<script type="text/javascript">
  $(document).ready(function(){
    var mydata = [{id:"1",name:"Roman C"}];
    //for(var i=0;i<=mydata.length;i++) $("#gridtable").jqGrid('addRowData',i+1,mydata[i]);
    $("#gridtable").jqGrid('setGridParam', {
        data: mydata
    }).trigger("reloadGrid");
  });
</script>

这篇关于Struts 2 jQuery网格从JSON字符串加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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