1

我正在使用 strust2 jquery 网格。我的问题是我的网格列名称直接来自 strust2 操作类或 DAO 类。网格动态形成基于DAO class.so 属性的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>

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

4

0 回答 0