A simple and complete demo of php + ajax + easyUIdatagrid

Source: Internet
Author: User
Tags database sharding
Find a simple and complete demo of php + ajax + easyUIdatagrid, such as the question, and find an instance that uses ajax to partially refresh the easyUI data table, which is simple and complete.


Reply to discussion (solution)

Here is a small demo, which is messy and I don't know how to use it.

User information 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 (array ("total" => 0, "rows" => array ()))); if ($ type = 'username' | $ type = 'nickname') {if ($ ty Pe = '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 ('Enter the correct user ID', '', true );} // determine the time $ startdate = strtotime ($ sdate); $ enddate = strtotime ($ edate); if (empty ($ startdate) | emp Ty ($ enddate) {$ this-> error ('Start time and end time cannot be blank ',', true);} if ($ startdate> $ enddate) {$ this-> error ('end time less than start time', '', true);} $ days = round ($ enddate-$ startdate)/3600/24 ); if ($ days> 7) {$ this-> error ('query data is longer than 7 days. we recommend that you query data less than 7 days ', '', true );} $ j = 0; $ exdata = explode ('-', $ sdate); $ gamemodel = $ this-> selDb ('log'); $ accs = array (); $ games = array (); for ($ I = strtotime ($ sdate); $ I <= strtotime ($ edate); $ I + = 8 6400) {$ y = mktime (, 0, $ exdata [1], $ exdata [2], $ exdata [0]); $ t = date ("Ymd ", $ y + $ j * 24*3600); $ j ++; // Database Sharding by days-> 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 = "sel Ect 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 );} // 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_log_date ']; $ vv ['tag'] = 'game '; $ brr [] = $ vv ;}}$ result = array_merge ($ arr, $ brr ); die (json_encode (array ('total' => count ($ result), "rows" => $ result? $ Result: array (); // query the comprehensive data in the game_win_log _ time and user_acount_change_log _ time tables.} $ 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! = Undefined) {vac. alert (r.info);} else {$ ("# datagrid "). datagrid ("loadData", r );}});} return value processing/** + callback * Ajax method to return data to the client + response * @ access protected + response * @ param mixed $ data to return data * @ param String $ info prompt information * @ param boolean $ status: returned status *@ Param String $ status ajax return type json xml + -------------------------------------------------------- * @ return void + response */protected function ajaxReturn ($ data, $ info = '', $ status = 1, $ type = '') {$ result = array (); $ result ['status'] = $ status; $ result ['info'] = $ info; $ result ['data'] = $ data; // extended ajax return data. define the function ajaxAssign (& $ result) {} method in the Action. Extended ajax return data. If (method_exists ($ this, 'ajaxassign') $ this-> ajaxAssign ($ result); if (empty ($ type )) $ type = C ('default _ AJAX_RETURN '); if (strtoupper ($ type) = 'json ') {// return the header ('content-Type: text/html; charset = utf-8 '); exit (json_encode ($ result) containing status information from the client in JSON format ));} elseif (strtoupper ($ type) = 'xml') {// return the XML format data header ('content-Type: text/xml; charset = utf-8 '); exit (xml_encode ($ result);} elseif (strtoupper ($ type) = 'eval') {// return the executable js script header ('content-Type: text/html; charset = utf-8 '); exit ($ data);} else {// add other formats to TODO }}

Update the specified row using the updateRow method of the easyui-grid control to achieve local update.

$('#dg').datagrid('updateRow',{index: 2,row: {name: 'new name',note: 'new note message'}});

The row data is obtained by ajax requests (you 'd better return json format instead of xml in php) and then use this method to perform partial update. for other details, see the official doc.

Update the specified row using the updateRow method of the easyui-grid control to achieve local update.

$('#dg').datagrid('updateRow',{index: 2,row: {name: 'new name',note: 'new note message'}});

The row data is obtained by ajax requests (you 'd better return json format instead of xml in php) and then use this method to perform partial update. for other details, see the official doc.
There is an easyUI datagrid on the page. how can I use ajax to update the data in this table?

View your js Post

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.