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 @ 2019-09-12 10:10  海乐学习  阅读(1227)  评论(0编辑  收藏  举报