Title, find an example of using Ajax to refresh the Easyui data table in a partial, simple and complete.
Reply to discussion (solution)
Here's a little demo, it's quite confusing.
User profile Public Function index () {//Search 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 ("=>0", "Rows" =>array ())); if ($type = = ' username ' | | $type = = ' nickname ') {if ($type = = ' username ') {$where = "user Name = ' ". $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 (' Please enter the correct user ID ', ' ', true '); }//Judgment Time $startdate =strtotime ($sdate); $enddate =strtotime ($edate); if (Empty ($startdate) | | empty ($enddate)) {$this->error (' Start time and end time cannot be empty ', "', true); if ($startdate > $enddate) {$this->error (' End time is less than start time ', ' ', true); } $days =round (($enddate-$startdate)/3600/24); if ($days >7) {$this->error (' query data is greater than 7 days, it is recommended to select less than 7 days for query ', ', true); } $j = 0; $exdata = Explode ('-', $sdate); $gamemodel = $this->seldb (' LOG '); $accs = Array (); $games = Array (); for ($i = Strtotime ($sdate), $i <= strtotime ($edate), $i + = 86400) {$y =mktime (0,0,0, $exdata [1], $exdata [2 ], $exdata [0]); $t =date ("Ymd", $y + $j *24*3600); $j + +; ->field (' Userid,moneychange,moneytype,ts,moneyfrom ') through the days of the library $sql 1 = "Select Userid,moneychange,moneytype,ts,moneyfrom,user_accunt_change_date from". $this->acctname. $t. "W Here 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 ($sql 1); }//merge data $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)) {//merge data foreach ($games as $k = + $v) {if (empty ($v)) {unset ($games [$k]); }else {foreach ($v as $kk = + $vv) {$VV [' data '] = $VV [' game_win_l Og_date ']; $VV [' flag '] = ' game '; $BRR [] = $VV; }}}} $result = Array_merge ($arr, $BRR); Die (Json_encode ("=>count" ($result), "rows" = = $result? $result: Array ())); Query game_win_log_ time and User_acount_change_log_ time two tables of comprehensive data} $this->display (); }jquery$ ("#datagrid"). DataGrid ("SelectRow", index), var row = $ ("#datagrid"). DatagrID ("getselected"); Search function Searchform () {//$ ("#datagrid"). DataGrid ("Load", Vac.serializeobject ($ ("#searchForm")); Vac.ajax ('/usermanage/index ', Vac.serializeobject ($ ("#searchForm")), ' POST ', function (r) {if (R.status! = Undefi Ned) {Vac.alert (r.info); }else{$ ("#datagrid"). DataGrid ("LoadData", R); } }); return value processing/** +----------------------------------------------------------* Ajax way to return data to client +------------------ ----------------------------------------* @access protected +---------------------------------------------------- ------* @param mixed $data The data to be returned * @param String $info Message * @param boolean $status return status * @param strin G $status Ajax return type JSON XML +----------------------------------------------------------* @return void +------ ----------------------------------------------------*/protected function Ajaxreturn ($data, $info = ", $staTus=1, $type = ') {$result = array (); $result [' status '] = $status; $result [' info '] = $info; $result [' data '] = $data; Extend the Ajax return data, define the function Ajaxassign (& $result) {} method in action to extend the Ajax return data. if (method_exists ($this, ' ajaxassign ')) $this->ajaxassign ($result); if (empty ($type)) $type = C (' Default_ajax_return '); if (Strtoupper ($type) = = ' json ') {//returns the JSON data format to the client that contains the status information header (' content-type:text/html; charset=utf -8 '); Exit (Json_encode ($result)); }elseif (Strtoupper ($type) = = ' xml ') {//Return XML Format Data header (' Content-type:text/xml; Charset=utf-8 '); Exit (Xml_encode ($result)); }elseif (Strtoupper ($type) = = ' EVAL ') {//returns the executable JS script header (' content-type:text/html; Charset=utf-8 '); Exit ($DATA); }else{//TODO Add other format}}
Use the Updaterow method of the Easyui-grid control to update the specified rows to achieve the effect of local updates
$ (' #dg '). DataGrid (' UpdateRow ', {index:2,row: {name: ' New name ', note: ' New Note message '}});
The data of its row is obtained by the AJAX request (the best thing you can do in PHP is to return the JSON format, not the XML) and use this method to update the local, other details of the official doc
Use the Updaterow method of the Easyui-grid control to update the specified rows to achieve the effect of local updates
$ (' #dg '). DataGrid (' UpdateRow ', {index:2,row: {name: ' New name ', note: ' New Note message '}});
The data of its row is obtained by the AJAX request (the best thing you can do in PHP is to return the JSON format, not the XML) and use this method to update the local, other details of the official doc
There is a easyui DataGrid in the page, how to use AJAX to update the table data?
See your JS section of the Post