easyui-datagrid 加载数据 的两种方法

复制代码
html部分

  <table id='grid' class='easyui-datagrid' style='width:100%;height:480px'
    title='列表' iconCls='icon-table' pagination='true' rownumbers='true' fitColumns='true' singleSelect='true' toolbar='#toolbar' >
    <thead>
      <tr>
        <th field='select' width='5' align='center'></th>
        <th field='UniqueId' width='13'align='center' hidden='true' >编号</th>
        <th field='CallerId' width='13' align='center'>主叫号码</th>
        <th field='Called' width='13' align='center'>被叫号码</th>
        <th field='CallType' width='10' align='center'>呼叫类型</th>

      </tr>
    </thead>
  </table>


js部份
var
start_date_entered=$('#start_date_entered').val(); //创建时间 var stop_date_entered=$('#stop_date_entered').val(); var callerid=$('#select_callerid').val(); var called=$('#select_called').val(); //查询条件 var query={ 'start_date_entered':start_date_entered,'stop_date_entered':stop_date_entered ,'callerid':callerid,'called':called };
复制代码
//方法一
var url='Api-index.php?module=<{$module_name}>&action=Api_GridView_Select<{$get_current_user}>' ;  //alert(url);
$('#grid').datagrid('options').url=url ; 
$('#grid').datagrid('options').queryParams=query;   
$('#grid').datagrid('reload');    
复制代码
//方法二
$.ajax({  
    type: "POST", //POST和GET  
    async: false,  
    url: 'Api-index.php?module=<{$module_name}>&action=Api_GridView_Select<{$get_current_user}>',    //提交url 注意url必须小写  
    data: query,  // { "SearchContent": query, "pageSize": pageSize, "pageIndex": curr }
    success: function (result) {  
        var data = $.parseJSON(result);//转为 Json对象    
        $('#grid').datagrid('loadData', data); 

     alert(data.total);//总行数 } });
复制代码
复制代码
//php 提交页
$table_name="ast_cdr";  
$arr_result = array(); //返回值  
$where='';//查询条件  
//日期条件    
$where=" and StartTime >='{$_POST['start_date_entered']}' and StartTime <='{$_POST['stop_date_entered']}' ";  
//其它条件
if($_POST['callerid']!=''){  
  $where .=" and CallerId = '{$_POST['callerid']}' ";   
} 
if($_POST['called']!=''){  
  $where .=" and Called = '{$_POST['called']}' ";   
}

//分页  
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;   
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;   
$offset = ($page-1)* $rows;   
    
$sql ="SELECT COUNT(id) AS total FROM {$table_name} where 1=1 " . $where ;   //WriteLog($sql);  
$arr_result['total'] =$db->query_count($sql);//总行数 
//WriteLog($result['total'].'-----' );  
    
//结果集      
$items = array();
         
$order_by=" order by StartTime desc ";/
$sql = "select * from {$table_name} where 1=1 ".$where .$order_by." limit $offset,$rows ";   
//WriteLog($sql);  
        
//导出

if($_GET['target']=="ToExcel" || $_GET['target']=="Print" ){ $arr_result['where'] = $where; //将条件 传出 $arr_result['order_by'] = $order_by; //将条件 传出 //WriteLog($where); //WriteLog($order_by); echo json_encode($arr_result); exit(0); } $result_rows=$db->query($sql); while($row=$db->fetch_array($result_rows)) { $select_title="放音";//iconv('GB2312','UTF-8','选择'); $row['select']='<a href="#" style="text-decoration:none;" onclick="javascript:Play_Record(\''. $row['UniqueId']. '\');"> ' . $select_title . ' </a>'; array_push($items, $row); }
$arr_result[
'rows'] = $items;
echo json_encode($arr_result);
复制代码

 

posted @   海乐学习  阅读(1238)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2010-09-12 PHP中的MYSQL常用函数
点击右上角即可分享
微信分享提示