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

一个简单的easyui datagrid初始化列名的问题
<script>
$('#sq').datagrid({ 
title:'Stores sales quantity performance',
    url: 'get_salesquantityper.php',
    singleSelect: true,
    rownumbers:true,
    frozenColumns:[[{field:'Category',title:'Category'}]],
        columns:'get_salesquantityper.php?type=initrows'
//  columns:[[{colspan:'3',title:'2013Dec'}],
//  [{field:'name',title:'Name', width:'80', align:'right'}, 
//  {field:'price',title:'Price',width:'80',align:'right'}, 
//  {field:'price',title:'Price',width:'80',align:'right'} 
//  ]] 
}); 
</script>

用js初始一个datagrid,目的是实现动态列。 列对应的columns属性,我看是个json就想绑定一个输出json的方法(get_salesquantityper.php?type=initrows)但在测试时什么都没输出,是绑定的方法错了? 如果要实现动态列该怎么做?
------解决方案--------------------
楼主怎么看的API。。column不能配置为url,没那么智能

自己先用ajax加载url获取到column后在配置datagrid

$.ajax({url:'xxxxxxxxxx',dataType:'json',success:function(data){
    $('#sq').datagrid({ 
        title:'Stores sales quantity performance',
        url: 'get_salesquantityper.php',
        singleSelect: true,
        rownumbers:true,
        frozenColumns:[[{field:'Category',title:'Category'}]],
        columns:data///xxxxxx那个页面输出column需要的内容
        }); 

},error:function(xhr){
  alert('动态页有问题或者返回了不标准的JSON字符串\n'+xhr.responseText);
}})