easyui-datagrid 加載數據 的兩種方法

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);
相關文章
相關標籤/搜索