2017-05-09 7 views
-1

行の数が907234でない限り、dataTableのデフォルトの動作は良好です。私はAjax指向の作業を使用したいので、ページあたり10レコードを取得したいと思います。AJAXソースを設定できます、ページングは​​未来のものになるでしょう。 (データテーブルがレコードの数を知りませんでしたか?だから始めるには?完全にAJAXベースのjQuery-dataTableを作成するには?

+1

私がしようとするでしょうあなたにオンラインのワーキングリンクを提供します。 –

答えて

2

のDataTableのサーバ側のアプローチは非常に似ている:

$('#dataTable').dataTable({ 
    "sServerMethod": "GET", 
    "bProcessing": true, 
    "bServerSide": true, 
    "sAjaxSource": "data.php", 
    "aoColumns": [null, null, null, { "bSortable": false }], 
    "order": [[ 1, "asc" ]], 
    "oLanguage": {"sZeroRecords": "No Members found", "sEmptyTable": "No members to display"}, 
}); 

バックエンドすなわちdata.phpはそうのようにする必要があります:

<?php 
      $start = $_GET['iDisplayStart']; 
      $length = $_GET['iDisplayLength']; 
      $sSearch = $_GET['sSearch']; 
      $col = $_GET['iSortCol_0']; 
      $arr = array(1 => 'oe.org_given_id', 2 => 'usr.name'); 
      $sort_by = $arr[$col]; 
      $sort_type = $_REQUEST['sSortDir_0']; 

      $query = "SELECT usr.id,usr.name,oe.org_given_id FROM users usr JOIN organization_employees oe on usr.id=oe.employee_id WHERE oe.organization_id=".$organization_id." AND (usr.name LIKE '%".$sSearch."%' OR oe.org_given_id LIKE '%".$sSearch."%') ORDER BY ".$sort_by." ".$sort_type." LIMIT ".$start.", ".$length; 
      $db=new DB(); 
      $resultSet=$db->SelectRead($query); 
      while($row = mysqli_fetch_assoc($resultSet)) 
      { 
       $data[] = $row; 
      } 
      $counterQuery = "SELECT COUNT(usr.id) as total FROM users usr JOIN organization_employees oe on usr.id=oe.employee_id WHERE oe.organization_id=".$organization_id.";"; 
      $countSet = $db->SelectRead($counterQuery); 
      $iTotal=0; 
      while($counterRow = mysqli_fetch_assoc($countSet)) 
      { 
       $iTotal = $counterRow['total']; 
      } 
      $rec = array(
       'iTotalRecords' => $iTotal, 
       'iTotalDisplayRecords' => $iTotal, 
       'aaData' => array() 
      ); 
      $k=0; 
      if (isset($data) && is_array($data)) 
      { 
       foreach ($data as $item) 
       { 
       $rec['aaData'][$k] = array(
             0 => $k, 
             1 => $item['org_given_id'], 
             2 => $item['name'], 
             3 => "Delete" 
            ); 
       $k++; 
       } 
      } 
      header("Content-type:application/json"); 
      echo json_encode($rec); 
?> 

のようなパラメータ: iDisplayStartiDisplayLengthなどがデフォルトですDatatablesによって与えられる。

一部のオンライン作業実施例は次のとおりです。

https://coderexample.com/datatable-demo-server-side-in-phpmysql-and-ajax/ http://phpflow.com/php/datatables-example-server-side-processing-with-php/ http://phpflow.com/demo/datatable/

私のコードのgithubのリポジトリがoffcourseいくつかの追加機能と以下の通りです:

https://github.com/shaktiphartiyal/DataTable-Editor-Free

関連する問題