日期:2014-05-16  浏览次数:20482 次

datagrid 动态生成列的问题
要求:根据用户选择的时间段动态生成列,如下

卡在了当用户选择时间段后点击‘go’按钮,该怎么修改datagrid中的列名?请大神用个简单的示例指点下
------解决方案--------------------
<div id="dvDataGrid">
<table id="salesquantityper"  class="easyui-datagrid" style="width:auto;height:220px" title="Stores sales quantity performance"
 data-options="url: 'get_salesquantityper.php', singleSelect: true,  rownumbers:true "      
 > 
<thead data-options="frozen:true"> 
<tr> 
<th data-options="field:'Category'"  width="100" ><strong>Category</strong></th>
</tr> 
</thead> 
<thead >
<tr>
<?php
//include "t.php";
initRows1($x1, $x2);//initRows1方法正确输出
?>
</tr> 
<tr> 
<?php 
initRows2($x1, $x2);
?> 
</tr> 
</thead> 
</table></div>

用个容器括起datagrid的容器,查询后清空容器里面easyui生成的datagrid代码,easyui没有提供更改columns配置的方法,也没有注销datagrid的方法,只能靠清空容器来移除datagrid了。如果你用的jqgrid有提供注销jqgrid的功能

点击查询
$('#dvDataGrid').html('<table id="salesquantityper"></table>')
//参考你另外的那个帖子,用ajax获取到columns的内容后重新调用$('#salesquantityper').datagrid()的方法生成datagrid对象加载columns新配和数据