一个简单的easyui datagrid初始化列名的问题 datagrideasyuijavascript 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼主怎么看的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);}}) 这是我输出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 你返回的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; 直接输出的话就,因为ajax中指定的是json格式,会执行这句代码error:function(xhr){ alert('动态页有问题或者返回了不标准的JSON字符串\n'+xhr.responseText); }已经验证了.... 我已经改过你的字符串称为标准json格式的了,你原来的那个不标准。 请问,这样生成的datagrid怎么更新数据?以往都是$('#sq').datagrid('reload',{bt:$('#bt').val(),et:$('#et').val()});但现在因为列名也要随数据一起跟新,该怎么写? 请问,这样生成的datagrid怎么更新数据?以往都是$('#sq').datagrid('reload',{bt:$('#bt').val(),et:$('#et').val()});但现在因为列名也要随数据一起跟新,该怎么写?看你php版块的帖子,清空datagrid的生成的html,放置一个空的table容器重新构造datagrid,你的url也要同时更新(如修改url参数什么的),重新加载数据还是你原来的方法 请问,这样生成的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); }})}在测试时后台能获得前台传来的数据但报错, 解决了,还是有问题。用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;//不能动态取得时间} jquery treeview (ul li) javascript 解析顺序问题 弹出小网页问题,一个页面点击第二个弹出链接时,弹出的网页不在当前? 如何实现行或者列中 文本框中整数值的累加 圖片按比例縮放問題 (100分)关于网络安全一个对大家都很有意义的问题!网站后台如何获得来访客户端的唯一标识符,例如网卡Mac地址?? 怎么用JS控制RADIO的初始值?少见! 如何取得子窗口的元素? 关于flash中的actionscript 问一个JS函数??帮帮吧 关于 jQuery validate 的一个自定义验证方法, 组合排列算法
$('#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);
}})
$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
$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;
error:function(xhr){
alert('动态页有问题或者返回了不标准的JSON字符串\n'+xhr.responseText);
}已经验证了....
$('#sq').datagrid('reload',{bt:$('#bt').val(),et:$('#et').val()});
但现在因为列名也要随数据一起跟新,该怎么写?
$('#sq').datagrid('reload',{bt:$('#bt').val(),et:$('#et').val()});
但现在因为列名也要随数据一起跟新,该怎么写?
看你php版块的帖子,清空datagrid的生成的html,放置一个空的table容器重新构造datagrid,你的url也要同时更新(如修改url参数什么的),重新加载数据还是你原来的方法
$('#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);
}})
}
在测试时后台能获得前台传来的数据但报错,
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;//不能动态取得时间
}