您好,欢迎访问一九零五行业门户网

求个php+ajax+easyUI datagrid的简单完整的demo

如题,求个用ajax局部刷新easyui数据表格的实例,简单完整就好
回复讨论(解决方案) 这里有个小demo,写得比较乱不知道怎么用
用户资料 public function index() { //搜索 if($this->isajax()) { $type = $_post['type']; $uservalue = $_post['uservalue']; $gametype = $_post['gametype']; $channeltype = $_post['channeltype']; $moneytype = $_post['moneytype']; $sdate = $_post['sdate']; $edate = $_post['edate']; if(empty($uservalue)) die(json_encode(array(total=>0,rows=>array()))); if ($type=='username' || $type == 'nickname') { if($type == 'username') { $where = username = '.$uservalue.'; }elseif($type == 'nickname') { $where = nick_name = '.$uservalue.'; } $userinfo = $this->model->where($where)->select(); $userid = $userinfo['userid']; }else { $userid = $uservalue; } if (empty($userid)) { $this->error('请输入正确的用户id','',true); } //判断时间 $startdate=strtotime($sdate); $enddate=strtotime($edate); if(empty($startdate) || empty($enddate)) { $this->error('开始时间和结束时间不能为空','',true); } if($startdate > $enddate) { $this->error('结束时间小于开始时间','',true); } $days=round(($enddate-$startdate)/3600/24) ; if($days >7) { $this->error('查询数据大于7天了,建议选择上小于7天进行查询','',true); } $j=0; $exdata = explode('-',$sdate); $gamemodel = $this->seldb('log'); $accs = array(); $games = array(); for($i = strtotime($sdate); $i field('userid,moneychange,moneytype,ts,moneyfrom') $sql1 =select userid,moneychange,moneytype,ts,moneyfrom,user_accunt_change_date from .$this->acctname.$t. where userid = '$userid' and moneytype in($moneytype) and moneyfrom in ($channeltype) group by userid,moneyfrom,moneytype; $sql =select userid,moneychange,moneytype,gameid,ts,moneyfrom,game_win_log_date from .$this->gamewinname.$t. where userid = '$userid' and moneytype in($moneytype) and moneyfrom in ($channeltype) and gameid in ($gametype) group by userid,gameid; $games[] = $gamemodel->query($sql); $accs[] = $gamemodel->query($sql1); } //合并数据 $arr = array(); $brr = array(); if(!empty($accs)) { foreach($accs as $k=>$v) { if(empty($v)) { unset($accs[$k]); }else { foreach($v as $kk=>$vv) { $vv['data'] = $vv['user_accunt_change_date']; $vv['flag'] = 'account'; $arr[] = $vv; } } } } if(!empty($games)) { //合并数据 foreach($games as $k=>$v) { if(empty($v)) { unset($games[$k]); }else { foreach($v as $kk=>$vv) { $vv['data'] = $vv['game_win_log_date']; $vv['flag'] = 'game'; $brr[] = $vv; } } } } $result = array_merge($arr,$brr); die(json_encode(array('total'=>count($result),rows=>$result?$result:array()))); //查询game_win_log_时间和user_acount_change_log_时间两个表中的综合数据 } $this->display(); }jquery$(#datagrid).datagrid(selectrow,index);var row = $(#datagrid).datagrid(getselected); //搜索 function searchform(){ //$(#datagrid).datagrid(load,vac.serializeobject($(#searchform)); vac.ajax('/usermanage/index', vac.serializeobject($(#searchform)), 'post', function(r){ if(r.status != undefined){ vac.alert(r.info); }else{ $(#datagrid).datagrid(loaddata,r); } }); }返回值处理 /** +---------------------------------------------------------- * ajax方式返回数据到客户端 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param mixed $data 要返回的数据 * @param string $info 提示信息 * @param boolean $status 返回状态 * @param string $status ajax返回类型 json xml +---------------------------------------------------------- * @return void +---------------------------------------------------------- */ protected function ajaxreturn($data,$info='',$status=1,$type='') { $result = array(); $result['status'] = $status; $result['info'] = $info; $result['data'] = $data; //扩展ajax返回数据, 在action中定义function ajaxassign(&$result){} 方法 扩展ajax返回数据。 if(method_exists($this,'ajaxassign')) $this->ajaxassign($result); if(empty($type)) $type = c('default_ajax_return'); if(strtoupper($type)=='json') { // 返回json数据格式到客户端 包含状态信息 header('content-type:text/html; charset=utf-8'); exit(json_encode($result)); }elseif(strtoupper($type)=='xml'){ // 返回xml格式数据 header('content-type:text/xml; charset=utf-8'); exit(xml_encode($result)); }elseif(strtoupper($type)=='eval'){ // 返回可执行的js脚本 header('content-type:text/html; charset=utf-8'); exit($data); }else{ // todo 增加其它格式 } }
使用easyui-grid控件的updaterow方法进行指定行的更新来达到局部更新的作用
$('#dg').datagrid('updaterow',{ index: 2, row: { name: 'new name', note: 'new note message' }});

其row的数据由ajax请求得到(你在php里面最好返回的是json格式,而不是xml) 再使用该方法去局部更新,其他详情自己看 官方doc
使用easyui-grid控件的updaterow方法进行指定行的更新来达到局部更新的作用
$('#dg').datagrid('updaterow',{ index: 2, row: { name: 'new name', note: 'new note message' }});

其row的数据由ajax请求得到(你在php里面最好返回的是json格式,而不是xml)   再使用该方法去局部更新,其他详情自己看 官方doc
在页面中有一个easyui的datagrid,怎么用ajax来更新这个表格的数据呢?
看你js版块的帖子
其它类似信息

推荐信息