欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery DataTable實(shí)現(xiàn)前后臺動(dòng)態(tài)分頁

 更新時(shí)間:2017年06月17日 17:07:29   作者:niko_sch  
本篇文章主要介紹了jquery DataTable實(shí)現(xiàn)前后臺動(dòng)態(tài)分頁。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

整理文檔,搜刮出一個(gè)jquery DataTable實(shí)現(xiàn)前后臺動(dòng)態(tài)分頁,稍微整理精簡一下做下分享。

html代碼:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>測試頁面</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link  rel="external nofollow" rel="stylesheet">
  <link  rel="external nofollow" rel="stylesheet">
  <link  rel="external nofollow" rel="stylesheet">


</head>
<body>
<div style="width:50%;height:500px;margin:150px auto ;background-color: #f4cccc">
<table id="example" class="display" cellspacing="0" width="100%">
  <thead>
  <tr>
    <th>Name</th>
    <th>Cellphone</th>
    <th>Position</th>
    <th>Company</th>
    <th>Salary</th>
  </tr>
  </thead>
  <tbody>

  </tbody>
</table>
</div>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.12.3.min.js"></script>
<script type="text/javascript" src=" //cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    refreshDataTable();
  });

 var refreshDataTable=function() {
   var table = $('#example').DataTable({
     //"ajax":"data/tabledata.json",
    // "iDisplayLength": 3,
     "sPaginationType": "full_numbers",
     "bPaginite": true,
     "bInfo": true,
     "bSort": true,
     "processing": false,
     "serverSide": true,
     "sAjaxSource": "customize/datatable.php",//這個(gè)是請求的地址
     "fnServerData": retrieveData

   });
   function retrieveData(url, aoData, fnCallback) {
     var data={"data":{"id":"123123","name":"2s",}};
     $.ajax({
       url: url,//這個(gè)就是請求地址對應(yīng)sAjaxSource
       data : {
         "aoData" : JSON.stringify(aoData)
       },
       type: 'POST',
       dataType: 'json',
       async: false,
       success: function (result) {

         //var obj=JSON.parse(result);
         console.log(result);
         fnCallback(result);//把返回的數(shù)據(jù)傳給這個(gè)方法就可以了,datatable會(huì)自動(dòng)綁定數(shù)據(jù)的
       },
       error:function(XMLHttpRequest, textStatus, errorThrown) {

         alert("status:"+XMLHttpRequest.status+",readyState:"+XMLHttpRequest.readyState+",textStatus:"+textStatus);

       }
     });
   }
 };
</script>
</body>
</html>

PHP代碼:

<?php
header('Content-type: text/json');
  $res = $_POST['aoData'];
 $sEcho = 0;
 $iDisplayStart = 0; // 起始索引
 $iDisplayLength = 0;//分頁長度
 $jsonarray= json_decode($res) ;
  foreach($jsonarray as $value){ 
  if($value->name=="sEcho"){
    $sEcho=$value->value;
  }
  if($value->name=="iDisplayStart"){
    $iDisplayStart=$value->value;
  }
  if($value->name=="iDisplayLength"){
    $iDisplayLength=$value->value;
  }
  }  
  $Array = Array(); 
   //此處生成50條數(shù)據(jù),模仿數(shù)據(jù)庫數(shù)據(jù)
  for ($i = 1; $i < 51; $i++) {
    $d = array($i,$i,$i,$i,$i);
    Array_push($Array, $d);
  }

   $json_data = array ('sEcho'=>$sEcho,'iTotalRecords'=>50,'iTotalDisplayRecords'=>50,'aaData'=>array_slice($Array,$iDisplayStart,$iDisplayLength)); //按照datatable的當(dāng)前頁和每頁長度返回json數(shù)據(jù)
  $obj=json_encode($json_data);
  echo $obj; 

?>

效果圖:

第一頁 

第二頁

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

  • jQuery和hwSlider實(shí)現(xiàn)內(nèi)容響應(yīng)式可觸控滑動(dòng)切換效果附源碼下載(二)

    jQuery和hwSlider實(shí)現(xiàn)內(nèi)容響應(yīng)式可觸控滑動(dòng)切換效果附源碼下載(二)

    這篇文章主要介紹了jQuery和hwSlider實(shí)現(xiàn)內(nèi)容響應(yīng)式可觸控滑動(dòng)切換效果附源碼下載(二)的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-06-06
  • js與jquery中獲取當(dāng)前鼠標(biāo)的x、y坐標(biāo)位置的代碼

    js與jquery中獲取當(dāng)前鼠標(biāo)的x、y坐標(biāo)位置的代碼

    jquery中獲取當(dāng)前鼠標(biāo)的x、y位置位置的代碼,需要的朋友可以參考下。
    2011-05-05
  • Jquery在指定DIV加載HTML示例代碼

    Jquery在指定DIV加載HTML示例代碼

    這篇文章主要介紹了Jquery如何在指定DIV加載HTML,需要的朋友可以參考下
    2014-02-02
  • Jquery操作下拉框(DropDownList)實(shí)現(xiàn)取值賦值

    Jquery操作下拉框(DropDownList)實(shí)現(xiàn)取值賦值

    Jquery操作下拉框(DropDownList)想必大家都有所接觸吧,下面與大家分享下對DropDownList進(jìn)行取值賦值的實(shí)現(xiàn)代碼
    2013-08-08
  • jQuery中的常用事件總結(jié)

    jQuery中的常用事件總結(jié)

    jquery中一些事件函數(shù)使用小結(jié),需要的朋友可以參考下。
    2009-12-12
  • 通過jQuery打造支持漢字,拼音,英文快速定位查詢的超級select插件

    通過jQuery打造支持漢字,拼音,英文快速定位查詢的超級select插件

    jQuery 超級select 插件 v3.0.0.0插件 支持漢字、拼音、英文快速定位查詢的超級select插件??煞较蜴I、tab 鍵快速選擇。
    2010-06-06
  • jQuery實(shí)現(xiàn)獲取h1-h6標(biāo)題元素值的方法

    jQuery實(shí)現(xiàn)獲取h1-h6標(biāo)題元素值的方法

    這篇文章主要介紹了jQuery實(shí)現(xiàn)獲取h1-h6標(biāo)題元素值的方法,涉及$(":header")選擇器操作h1-h6元素及事件響應(yīng)相關(guān)技巧,需要的朋友可以參考下
    2017-03-03
  • jQuery實(shí)現(xiàn)電梯導(dǎo)航模塊

    jQuery實(shí)現(xiàn)電梯導(dǎo)航模塊

    這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)電梯導(dǎo)航模塊,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-12-12
  • jQuery實(shí)現(xiàn)簡單飛機(jī)大戰(zhàn)

    jQuery實(shí)現(xiàn)簡單飛機(jī)大戰(zhàn)

    這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)簡單飛機(jī)大戰(zhàn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • 最新評論