动态设置struts2动作类的struts2 jquery网格列名

时间:2012-08-07 09:32:14

标签: json struts2 jqgrid

我正在使用strust2 jquery网格。我的问题是我的网格列名直接来自strust2动作类或DAO类。网格基于DAO类动态形成.DAO类的属性动态设置为网格列名。

 function sample()
 {
      $("#reloadgrid").jqGrid('setGridParam',{ datatype: 'json',page:1});
      $.publish('reloadgrid1');
      return false; 
 }
$.subscribe('reloadgrid1', function(event,element) 
{

var selRowIds=new Array();
var id=new Array();
var disc=new Array();
var data=new Array();
var ret=new Array();
var selRowIds=$('#reloadgrid').jqGrid('getDataIDs');
if(selRowIds.length<=selRowIds.length)
{
for( var i=0;i<selRowIds.length;i++){
        ret[i] = $("#reloadgrid").jqGrid('getRowData',selRowIds[i]); 
       id[i]=ret[i].id;
       disc[i]=ret[i].disc;
       data[i]=ret[i].data;
     if(disc[i]==null||data[i]==null||disc[i]==""||data[i]=="")
     {
         alert("Please enter values into grid");
        return false;
     }       
}
} 
     var totrec=$('#reloadgrid').jqGrid('getGridParam','reccount');
  //    alert(totrec);
        $("#reloadgrid").jqGrid('setGridParam',{ datatype: 'json'});
        $("#reloadgrid").jqGrid('setGridParam',{ postData:
                                                {
                                                 id:id,
                                                 disc:disc,
                                                 data:data,
                                                 reccount:totrec},
                                                 url: "finalAction"
                                                }).trigger('reloadGrid');

    });
   $.subscribe('rowselect', function(event, data)
    {

        var id=event.originalEvent.id;
        alert(id);
        var gr = $("#reloadgrid").jqGrid('getGridParam','selrow');

         if(gr)
        {
         $('#reloadgrid').jqGrid('editRow',gr,true);

         }
    });
       function formatLink(cellvalue, options, rowObject) {
        return "<input type='button' value='save' onClick='return saverow()'>                    
       <input type='button' value='delete' onClick='return deleterow()'>";
  }
  function saverow()
  {
var gr = $("#reloadgrid").jqGrid('getGridParam','selrow');
if(gr!=null)
{   
$('#reloadgrid').jqGrid('saveRow',gr);
return true;
}
else
{    
return false;
} 
return false;
 }
    function deleterow()
  {
alert("Confirm deletion");
var gr = $("#reloadgrid").jqGrid('getGridParam','selrow');
    if(gr!=null)
   {    
     $("#reloadgrid").jqGrid('delGridRow',gr);
   }

   }

 </script>


 <body style="margin: 0px; padding: 0px; font-family: 'Trebuchet MS',verdana;">


 <s:actionerror></s:actionerror>

  <s:form id="simpleForm" action="finalAction">
  <s:url var="gridid" action="gridAction" >
   </s:url>   
  <s:url var="editid" action="EditAction"/>
    <s:url var="finalid" action="finalAction"/>
  </s:form>

    <sjg:grid gridModel="gridmodelsample"
      id="reloadgrid"
      dataType="json"
      loadonce="true"
      href="%{gridid}"
      rowNum="3"
      gridview="true"
      width="600"
      viewrecords="true"
      editinline="true"
      editurl="%{editid}"
      navigator="false"
      navigatorEdit="false"
      navigatorView="false"
      navigatorAdd="false"
      onSelectRowTopics="rowselect"
      navigatorDelete="false"
      navigatorInlineEditButtons="true"
      caption="jQuery Inline Editing Grid"
      pager="true"
      multiselect="false"
      rowList="5,10,15,20"
      reloadTopics="reloadgrid"
      onGridCompleteTopics="createbuttons">
     <sjg:gridColumn name="editoperation" title="" formatter="formatLink">               </sjg:gridColumn>

</sjg:grid>

<sj:submit button="true" name="save" onClick="return sample()" value="save"/>

  </body>
</html>

我的问题是网格列名称动态来自动作类,并设置为网格列标题或标题。

0 个答案:

没有答案