zoukankan      html  css  js  c++  java
  • ThinkPHP+jQuery EasyUI Datagrid查询数据的简单处理

    ThinkPHP和jQuery EasyUI这两个都是不错的框架,现在要把它两个整合到一块,做个简单的Ajax调用查询。

    在ThinkPHP模板中引入EasyUI的相关文件,然后设置按钮3的调用:

     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    
            "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    <head>
        <title>easyui app</title>
        <link id="easyuiTheme" rel="stylesheet" type="text/css" href="__PUBLIC__/js/jquery-easyui-1.4.1/themes/{$_COOKIE.easyuiThemeName|default="default"}/easyui.css">
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/js/jquery-easyui-1.4.1/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/js/jquery-easyui-1.4.1/themes/icon.css">
        <script type="text/javascript" src="__PUBLIC__/js/jquery-easyui-1.4.1/jquery.min.js"></script>
        <script type="text/javascript" src="__PUBLIC__/js/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
            
    <script type="text/javascript">
        $(function(){
           //$.messager.alert('提示信息','Hello,Garfield !');
    
           $("#b1").click(function(){  
             $('#test').html('button1 click'); 
              });  
    
           $("#b2").click(function(){  
             $('#test').html('button2 click'); 
              });  
    
           
           $("#b3").click(function(){  
    
                   $('#mygrid').datagrid({
    
                       title:'Hello garfield',
                       320,
                    //直接读取数据
                    //url:'__PUBLIC__/data/datagrid_data1.json',    
                    url:'{:U("Index/read")}',    
                    columns:[[    
                        {field:'productid',title:'Code',100},    
                        {field:'productname',title:'Name',100},    
                        {field:'listprice',title:'Price',100,align:'right'}    
                    ]]    
                   });   
    
              }); 
    
           
        });
      </script>
        <script type="text/javascript" src="__TMPL__/Index/initApp.js" charset="utf-8"></script>
    </head>
    <body>
        <button id='b1'>Button1</button>
        <button id='b2'>Button2</button>
        <div id='test'>
            This is a div !
        </div>
    
        <button id='b3'>Button3</button>
        <table id='mygrid'></table>
    </body>
    </html>

    ThinkPHP后台控制器增加read方法:

    <?php
    namespace HomeController;
    use ThinkController;
    class IndexController extends Controller {
        public function index(){
            //$this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>!</p><br/>[ 您现在访问的是Home模块的Index控制器 ]</div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
            $this->display();
        }
    
        public function read(){
            $total=2;
    
            $userlist[0]['productid']='prd1';
            $userlist[0]['productname']='prdname1';
            $userlist[0]['listprice']='10';
    
            $userlist[1]['productid']='prd2';
            $userlist[1]['productname']='prdname2';
            $userlist[1]['listprice']='20';
    
            $json='{"total":'.$total.',"rows":'.json_encode($userlist).'}';//重要,easyui的标准数据格式,数据总数和数据内容在同一个json中
            echo $json;
    
        }
    }


    注意:前台模板中使用按钮来调用后台的数据查询,后台使用简单的一个数组来返回前台的数据格式。这里要注意前台的JSON格式。

  • 相关阅读:
    www.insidesql.org
    kevinekline----------------- SQLSERVER MVP
    Sys.dm_os_wait_stats Sys.dm_performance_counters
    如何使用 DBCC MEMORYSTATUS 命令来监视 SQL Server 2005 中的内存使用情况
    VITAM POST MORTEM – ANALYZING DEADLOCKED SCHEDULERS MINI DUMP FROM SQL SERVER
    Cargo, Rust’s Package Manager
    建筑识图入门(初学者 入门)
    Tracing SQL Queries in Real Time for MySQL Databases using WinDbg and Basic Assembler Knowledge
    Microsoft SQL Server R Services
    The Rambling DBA: Jonathan Kehayias
  • 原文地址:https://www.cnblogs.com/GarfieldTom/p/4252438.html
Copyright © 2011-2022 走看看