解决方案 »

  1.   

    楼主怎么看的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);
    }})
      

  2.   

    这是我输出json的代码
    $stt="[[{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'}]]";
    //$stt='[[{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"}]]';
    //echo json_encode($a);
    //echo $stt;
     echo json_encode($stt);
    返回的json总是带两个引号,页面也不能正常显示。 是转换错了吗?下面这个问题您一起把分拿走吧
    http://bbs.csdn.net/topics/390729264
      

  3.   

    你返回的json格式的字符串不标准,导致jquery没有执行succes回调
    $stt='[[{"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"}]]';
    //直接输出就好了,不用json_encode,你的不是对象,是字符串
     echo $stt;
      

  4.   

    直接输出的话就,因为ajax中指定的是json格式,会执行这句代码
    error:function(xhr){
      alert('动态页有问题或者返回了不标准的JSON字符串\n'+xhr.responseText);
    }已经验证了....
      

  5.   

    我已经改过你的字符串称为标准json格式的了,你原来的那个不标准。
      

  6.   

    请问,这样生成的datagrid怎么更新数据?以往都是
    $('#sq').datagrid('reload',{bt:$('#bt').val(),et:$('#et').val()});
    但现在因为列名也要随数据一起跟新,该怎么写?
      

  7.   

    请问,这样生成的datagrid怎么更新数据?以往都是
    $('#sq').datagrid('reload',{bt:$('#bt').val(),et:$('#et').val()});
    但现在因为列名也要随数据一起跟新,该怎么写?
    看你php版块的帖子,清空datagrid的生成的html,放置一个空的table容器重新构造datagrid,你的url也要同时更新(如修改url参数什么的),重新加载数据还是你原来的方法
      

  8.   

    请问,这样生成的datagrid怎么更新数据?以往都是
    $('#sq').datagrid('reload',{bt:$('#bt').val(),et:$('#et').val()});
    但现在因为列名也要随数据一起跟新,该怎么写?
    看你php版块的帖子,清空datagrid的生成的html,放置一个空的table容器重新构造datagrid,你的url也要同时更新(如修改url参数什么的),重新加载数据还是你原来的方法
    点击查询按钮时触发下面的事件(用于生成新的表格列名和表中的数据)
    function getD()

    $('#divDatagrid').html('<table id="salesquantityper"></table>');
    alert($('#bt').val());
      $.ajax({url:'get_salesquantityper.php?type=initrows',
      type:"POST",
      dataType:'json',
      data:{bt:$('#bt').val(),et:$('#et').val()}
      ,success:function(data){
       $('#salesquantityper').datagrid({ 
           title:'Stores sales quantity performance',
           url: 'get_salesquantityper.php',
           width:'auto',
           singleSelect: true,
           rownumbers:true,
           frozenColumns:[[{field:'Category',title:'Category'}]],
           columns:data
           });  },error:function(xhr){
     alert('动态页有问题或者返回了不标准的JSON字符串\n'+xhr.responseText);
    }})
    }
    在测试时后台能获得前台传来的数据但报错,
      

  9.   

    解决了,还是有问题。用jquery生成的datagrid中的数据不是动态的。
    function getD()

    $('#divDatagrid').html('<table id="salesquantityper"></table>');
    // alert($('#bt').val());
      $.ajax({url:'get_salesquantityper.php?type=initrows',
      type:"POST",
      dataType:'json',
      data:{bt:$('#bt').val(),et:$('#et').val()}//这句代码已经把bt和et传到了后台(get_salesquantityper.php)
      ,success:function(data){
       $('#salesquantityper').datagrid({ 
           title:'Stores sales quantity performance',
           url: 'get_salesquantityper.php',//这里却取不到动态的数据
           width:'auto',
           singleSelect: true,
           rownumbers:true,
           frozenColumns:[[{field:'Category',title:'Category'}]],
           columns:data
           }); 
      // $('#salesquantityper').datagrid('reload',{bt:$('#bt').val(),et:$('#et').val()}); },error:function(xhr){
     alert('ajax error\n'+xhr.responseText);
    }})
    }后台代码
    include_once 'DB_connmssql.php';
    $l_mb =str_replace('-','',date("Y-m-d",strtotime("-3 month")));
    $l_me= str_replace('-','', date("Y-m-d",strtotime("-0 month")));$start_date = isset($_POST['bt']) ? substr(str_replace('-','',$_POST['bt']),0,6):substr($l_mb,0,6);
    $end_date = isset($_POST['et']) ? substr(str_replace('-', '',$_POST['et']),0,6) :substr($l_me,0,6);$type=$_REQUEST['type'];if($type=='initrows'){

    //echo $start_date."@^^@".$end_date;能动态取得时间
    echo initRows4(xx1($start_date),xx1($end_date),1);
    }else{
    echo $start_date."@@@".$end_date;//不能动态取得时间
    }